diff --git a/README.md b/README.md new file mode 100644 index 0000000..170c6a3 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +## NextSync + diff --git a/src/commands/add.rs b/src/commands/add.rs index bdbcf88..7d9f00f 100644 --- a/src/commands/add.rs +++ b/src/commands/add.rs @@ -1,5 +1,6 @@ use clap::Values; -use crate::utils::{self, nextsyncignore}; +use crate::utils::{self}; +use crate::utils::nextsyncignore::{self, ignore_file, ignore_files}; use crate::store; use std::path::{Path, PathBuf}; use std::io::Write; @@ -12,13 +13,21 @@ pub struct AddArgs<'a> { pub fn add(args: AddArgs) { let mut index_file = store::index::open(); let mut added_files: Vec = vec![]; - + let rules = match nextsyncignore::read_lines() { + Ok(r) => r, + Err(_) => vec![], + }; + let mut ignored_f = vec![]; let file_vec: Vec<&str> = args.files.collect(); for file in file_vec { + if !args.force && ignore_file(&file.to_string(), rules.clone(), &mut ignored_f) { + continue; + } let path = Path::new(file); match path.exists() { true => { if path.is_dir() { + added_files.push(String::from(path.to_str().unwrap())); add_folder_content(path.to_path_buf(), &mut added_files); } else { @@ -32,19 +41,16 @@ pub fn add(args: AddArgs) { } } - // check ignored file if not forced - if !args.force { - let (ignored, ignored_files) = nextsyncignore::ignore_files(&mut added_files); - if ignored { - // todo multiple nextsyncignore - println!("The following paths are ignored by your .nextsyncignore file:"); - for file in ignored_files { - println!("{}", file); - } + if ignored_f.len() > 0 { + // todo multiple nextsyncignore + println!("The following paths are ignored by your .nextsyncignore file:"); + for file in ignored_f { + println!("{}", file); } } // save all added_files in index + // todo avoid duplication for file in added_files { match writeln!(index_file, "{}", file) { Ok(()) => (), diff --git a/src/commands/clone.rs b/src/commands/clone.rs index d998bc6..6e8a4df 100644 --- a/src/commands/clone.rs +++ b/src/commands/clone.rs @@ -85,7 +85,7 @@ pub fn clone(remote: Values<'_>) { // find folders and files in response let objects = get_objects_xml(body); let mut iter = objects.iter(); - iter.next(); // jump first element which the folder fetched + iter.next(); // jump first element which is the folder cloned for object in iter { if object.chars().last().unwrap() == '/' { folders.push(object.to_string()); diff --git a/src/utils/nextsyncignore.rs b/src/utils/nextsyncignore.rs index 2957c36..8b1d62d 100644 --- a/src/utils/nextsyncignore.rs +++ b/src/utils/nextsyncignore.rs @@ -3,7 +3,7 @@ use regex::Regex; use std::fs::File; use std::io::{Cursor, BufReader, BufRead}; -fn read_lines() -> Result, ()> { +pub fn read_lines() -> Result, ()> { if let Some(path) = path::nextsyncignore() { let file = match File::open(path) { Ok(buffer) => buffer,