diff --git a/src/commands/clone.rs b/src/commands/clone.rs index 293902d..3895935 100644 --- a/src/commands/clone.rs +++ b/src/commands/clone.rs @@ -1,10 +1,8 @@ -use std::env; use std::fs::OpenOptions; use std::fs::DirBuilder; use std::io::prelude::*; use std::io::Cursor; use std::path::{Path, PathBuf}; -use std::ffi::OsStr; use clap::Values; use regex::Regex; use xml::reader::{EventReader, XmlEvent}; @@ -39,7 +37,6 @@ pub fn clone(remote: Values<'_>) { lp }, }; - dbg!((local_path.clone())); let mut folders = vec![String::from(dist_path_str)]; let mut url_request; @@ -70,12 +67,11 @@ pub fn clone(remote: Values<'_>) { // destination path 'path' already exists and is not an empty directory. //std::process::exit(1); } else { - dbg!(local_path.to_str()); - commands::init::init(Some(local_path.to_str().unwrap())); + commands::init::init(); } } else { // create folder - let mut local_folder = get_local_path(folder, local_path.clone(), username, dist_path_str); + let local_folder = get_local_path(folder, local_path.clone(), username, dist_path_str); dbg!(DirBuilder::new().recursive(true).create(local_folder.clone())); // add tree @@ -104,7 +100,7 @@ fn get_local_path(p: String, local_p: PathBuf, username: &str, dist_p: &str) -> let mut final_p = Path::new(p.as_str()); final_p = final_p.strip_prefix("/remote.php/dav/files/").unwrap(); final_p = final_p.strip_prefix(username.clone()).unwrap(); - let mut dist_p = Path::new(dist_p).strip_prefix("/"); + let dist_p = Path::new(dist_p).strip_prefix("/"); final_p = final_p.strip_prefix(dist_p.unwrap()).unwrap(); local_p.clone().join(final_p.clone()) } diff --git a/src/commands/init.rs b/src/commands/init.rs index 39c46b1..62e84c7 100644 --- a/src/commands/init.rs +++ b/src/commands/init.rs @@ -3,9 +3,9 @@ use std::path::PathBuf; use std::env; use crate::global::global::DIR_PATH; -pub fn init(directory: Option<&str>) { +pub fn init() { let d = DIR_PATH.lock().unwrap(); - dbg!(d.clone()); + let mut path = match d.clone() { Some(dir) => PathBuf::from(dir), None => env::current_dir().unwrap(), diff --git a/src/main.rs b/src/main.rs index 185a0c7..598d04b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,10 +52,7 @@ fn main() { if let Some(val) = matches.values_of("directory") { global::global::set_dir_path(String::from(val.clone().next().unwrap())); } - match matches.values_of("directory") { - Some(d) => commands::init::init(d.clone().next()), - None => commands::init::init(None), - } + commands::init::init(); } else if let Some(_) = matches.subcommand_matches("status") { commands::status::status(); } else if let Some(matches) = matches.subcommand_matches("add") { diff --git a/src/utils/head.rs b/src/utils/head.rs index 543351f..d3ab9a4 100644 --- a/src/utils/head.rs +++ b/src/utils/head.rs @@ -30,7 +30,7 @@ pub fn add_line(line: String) -> io::Result<()> { Some(path) => path, None => todo!(), }; - dbg!(root.clone()); + root.push(".nextsync"); root.push("HEAD"); diff --git a/src/utils/object.rs b/src/utils/object.rs index e5b5b24..5eabcef 100644 --- a/src/utils/object.rs +++ b/src/utils/object.rs @@ -1,5 +1,4 @@ use std::path::Path; -use std::path::PathBuf; use crate::utils::{head, path}; use crypto::sha1::Sha1; use crypto::digest::Digest; @@ -8,7 +7,6 @@ use std::io::Write; use std::io; pub fn add_tree(path: &Path) { - dbg!(path.clone()); let file_name = path.file_name().unwrap().to_str().unwrap(); let mut hasher = Sha1::new(); hasher.input_str(path.clone().to_str().unwrap()); @@ -22,7 +20,6 @@ pub fn add_tree(path: &Path) { dbg!(add_node(path.parent().unwrap(), &line)); } dbg!(add_file(hash, file_name)); - dbg!(path.iter().count()); } fn add_node(path: &Path, node: &str) -> io::Result<()> {