diff --git a/src/commands/clone.rs b/src/commands/clone.rs index 80ff2c8..ded411d 100644 --- a/src/commands/clone.rs +++ b/src/commands/clone.rs @@ -17,6 +17,10 @@ pub fn clone(remote: Values<'_>) { let url = remote.clone().next().unwrap(); let (domain, tmp_user, path_str) = get_url_props(url); let path = Path::new(path_str); + let mut iter_path = path.iter(); + iter_path.next(); // go through the / + let dest_dir = iter_path.next().unwrap(); + let dest_path = std::env::current_dir().unwrap().join(dest_dir); let username = match tmp_user { Some(u) => u, None => { @@ -55,7 +59,7 @@ pub fn clone(remote: Values<'_>) { // destination path 'path' already exists and is not an empty directory. //std::process::exit(1); } else { - commands::init::init(Some(env::current_dir().unwrap().to_str().unwrap())); + commands::init::init(Some(dest_path.to_str().unwrap())); } } else { let mut path = Path::new(&folder).strip_prefix("/remote.php/dav/files/"); @@ -67,10 +71,8 @@ pub fn clone(remote: Values<'_>) { if !first_iter { let mut path_folder = Path::new(&folder).strip_prefix("/remote.php/dav/files/"); path_folder = path_folder.unwrap().strip_prefix(username); - let mut root = path_folder.clone().unwrap().iter(); - let o = root.next(); - path_folder = path_folder.unwrap().strip_prefix(o.unwrap()); - object::add_tree(&path_folder.unwrap()); + path_folder = path_folder.unwrap().strip_prefix(dest_dir.clone()); + object::add_tree(&path_folder.unwrap(), Some(dest_path.clone())); } // find folders and files in response diff --git a/src/utils/head.rs b/src/utils/head.rs index 3c1f9da..543351f 100644 --- a/src/utils/head.rs +++ b/src/utils/head.rs @@ -30,6 +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 35d671f..9713fb9 100644 --- a/src/utils/object.rs +++ b/src/utils/object.rs @@ -1,4 +1,5 @@ use std::path::Path; +use std::path::PathBuf; use crate::utils::{head, path}; use crypto::sha1::Sha1; use crypto::digest::Digest; @@ -6,7 +7,7 @@ use std::fs::{OpenOptions, self}; use std::io::Write; use std::io; -pub fn add_tree(path: &Path) { +pub fn add_tree(path: &Path, src: Option) { dbg!(path.clone()); let file_name = path.file_name().unwrap().to_str().unwrap(); let mut hasher = Sha1::new();