diff --git a/src/commands/clone.rs b/src/commands/clone.rs index 4ff0768..9c5a6b3 100644 --- a/src/commands/clone.rs +++ b/src/commands/clone.rs @@ -10,7 +10,6 @@ use crate::services::api::ApiError; use crate::services::list_folders::ListFolders; use crate::services::download_files::DownloadFiles; use crate::utils::object; -use crate::utils::path; use crate::commands; use crate::global::global::{DIR_PATH, set_dir_path}; @@ -72,11 +71,15 @@ pub fn clone(remote: Values<'_>) { } else { // create folder let local_folder = get_local_path(folder, local_path.clone(), username, dist_path_str); - dbg!(DirBuilder::new().recursive(true).create(local_folder.clone())); + if let Err(err) = DirBuilder::new().recursive(true).create(local_folder.clone()) { + eprintln!("error: cannot create directory {}: {}", local_folder.display(), err); + } // add tree let path_folder = local_folder.strip_prefix(local_path.clone()).unwrap(); - object::add_tree(&path_folder); + if object::add_tree(&path_folder).is_err() { + eprintln!("error: cannot store object {}", path_folder.display()); + } } // find folders and files in response @@ -114,7 +117,7 @@ fn write_file(path: PathBuf, content: &Vec, local_p: PathBuf) -> io::Result< f.write_all(&content)?; let relative_p = Path::new(&path).strip_prefix(local_p).unwrap(); - object::add_blob(relative_p, "tmpdate"); + object::add_blob(relative_p, "tmpdate")?; Ok(()) } diff --git a/src/commands/config.rs b/src/commands/config.rs index 2536f75..0b17a12 100644 --- a/src/commands/config.rs +++ b/src/commands/config.rs @@ -1,9 +1,9 @@ use crate::utils::path; use crate::utils::read; use std::fs::OpenOptions; -use std::io::Write; +use std::io::{self, Write}; -pub fn set(var: &str, val: &str) { +pub fn set(var: &str, val: &str) -> io::Result<()> { let mut root = match path::nextsync() { Some(path) => path, None => { @@ -19,12 +19,13 @@ pub fn set(var: &str, val: &str) { .write(true) .create(true) .append(true) - .open(root).unwrap(); + .open(root)?; let mut line = var.to_owned(); line.push_str(" "); line.push_str(val); - writeln!(file, "{}", line); + writeln!(file, "{}", line)?; + Ok(()) } pub fn get(var: &str) -> Option { diff --git a/src/commands/status.rs b/src/commands/status.rs index 5655b31..0bd5979 100644 --- a/src/commands/status.rs +++ b/src/commands/status.rs @@ -4,7 +4,6 @@ use crypto::sha1::Sha1; use std::collections::HashMap; use colored::Colorize; use std::path::PathBuf; -use std::path::Path; use std::io::{self, Lines, BufReader}; use crate::utils::{self, object}; @@ -45,9 +44,7 @@ pub fn get_diff() -> (Vec, Vec, Vec) { dbg!(utils::path::current()); let nextsync_path = utils::path::nextsync().unwrap(); let current_p = utils::path::current().unwrap(); - let mut dist_path = current_p.strip_prefix(root.clone()).unwrap().to_path_buf(); - dbg!(dist_path.clone()); - + let dist_path = current_p.strip_prefix(root.clone()).unwrap().to_path_buf(); if let Ok(lines) = read_head(nextsync_path.clone()) { add_to_hashmap(lines, &mut hashes, dist_path.clone()); diff --git a/src/main.rs b/src/main.rs index aa80cbe..db6822d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -100,7 +100,9 @@ fn main() { } else if let Some(matches) = matches.subcommand_matches("config") { if let Some(mut var) = matches.values_of("variable") { if let Some(mut val) = matches.values_of("value") { - commands::config::set(var.next().unwrap(), val.next().unwrap()); + if commands::config::set(var.next().unwrap(), val.next().unwrap()).is_err() { + eprintln!("fatal: cannot save the value"); + } } } } diff --git a/src/utils/object.rs b/src/utils/object.rs index c715bca..19bf0e5 100644 --- a/src/utils/object.rs +++ b/src/utils/object.rs @@ -132,16 +132,12 @@ fn add_node(path: &Path, node: &str) -> io::Result<()> { let (dir, rest) = hash_obj(path.clone().to_str().unwrap()); - dbg!(root.clone()); root.push(dir); if !root.exists() { todo!(); } root.push(rest); - dbg!("create node"); - dbg!(root.clone()); - dbg!(node.clone()); let mut file = OpenOptions::new() .read(true) .write(true)