fix init when cloning in the right dir

This commit is contained in:
grimhilt 2023-06-06 15:35:53 +02:00
parent 3b629f6de7
commit 457dd32ad8
3 changed files with 10 additions and 6 deletions

View File

@ -17,6 +17,10 @@ pub fn clone(remote: Values<'_>) {
let url = remote.clone().next().unwrap(); let url = remote.clone().next().unwrap();
let (domain, tmp_user, path_str) = get_url_props(url); let (domain, tmp_user, path_str) = get_url_props(url);
let path = Path::new(path_str); 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 { let username = match tmp_user {
Some(u) => u, Some(u) => u,
None => { None => {
@ -55,7 +59,7 @@ pub fn clone(remote: Values<'_>) {
// destination path 'path' already exists and is not an empty directory. // destination path 'path' already exists and is not an empty directory.
//std::process::exit(1); //std::process::exit(1);
} else { } else {
commands::init::init(Some(env::current_dir().unwrap().to_str().unwrap())); commands::init::init(Some(dest_path.to_str().unwrap()));
} }
} else { } else {
let mut path = Path::new(&folder).strip_prefix("/remote.php/dav/files/"); let mut path = Path::new(&folder).strip_prefix("/remote.php/dav/files/");
@ -67,10 +71,8 @@ pub fn clone(remote: Values<'_>) {
if !first_iter { if !first_iter {
let mut path_folder = Path::new(&folder).strip_prefix("/remote.php/dav/files/"); let mut path_folder = Path::new(&folder).strip_prefix("/remote.php/dav/files/");
path_folder = path_folder.unwrap().strip_prefix(username); path_folder = path_folder.unwrap().strip_prefix(username);
let mut root = path_folder.clone().unwrap().iter(); path_folder = path_folder.unwrap().strip_prefix(dest_dir.clone());
let o = root.next(); object::add_tree(&path_folder.unwrap(), Some(dest_path.clone()));
path_folder = path_folder.unwrap().strip_prefix(o.unwrap());
object::add_tree(&path_folder.unwrap());
} }
// find folders and files in response // find folders and files in response

View File

@ -30,6 +30,7 @@ pub fn add_line(line: String) -> io::Result<()> {
Some(path) => path, Some(path) => path,
None => todo!(), None => todo!(),
}; };
dbg!(root.clone());
root.push(".nextsync"); root.push(".nextsync");
root.push("HEAD"); root.push("HEAD");

View File

@ -1,4 +1,5 @@
use std::path::Path; use std::path::Path;
use std::path::PathBuf;
use crate::utils::{head, path}; use crate::utils::{head, path};
use crypto::sha1::Sha1; use crypto::sha1::Sha1;
use crypto::digest::Digest; use crypto::digest::Digest;
@ -6,7 +7,7 @@ use std::fs::{OpenOptions, self};
use std::io::Write; use std::io::Write;
use std::io; use std::io;
pub fn add_tree(path: &Path) { pub fn add_tree(path: &Path, src: Option<PathBuf>) {
dbg!(path.clone()); dbg!(path.clone());
let file_name = path.file_name().unwrap().to_str().unwrap(); let file_name = path.file_name().unwrap().to_str().unwrap();
let mut hasher = Sha1::new(); let mut hasher = Sha1::new();