This commit is contained in:
grimhilt 2023-06-06 19:47:15 +02:00
parent 762ab25619
commit c5abc57e9a
5 changed files with 7 additions and 17 deletions

View File

@ -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())
}

View File

@ -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(),

View File

@ -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") {

View File

@ -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");

View File

@ -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<()> {