diff --git a/src/commands/clone.rs b/src/commands/clone.rs index cb31ca1..8b57564 100644 --- a/src/commands/clone.rs +++ b/src/commands/clone.rs @@ -178,7 +178,7 @@ mod tests { fn test_get_url_props() { let p = "/foo/bar"; let u = Some("user"); - let d = String::from("http://nextcloud.com"); + // let d = String::from("http://nextcloud.com"); let sd = String::from("https://nextcloud.com"); let sld = String::from("https://nextcloud.example.com"); let ld = String::from("http://nextcloud.example.com"); diff --git a/src/commands/config.rs b/src/commands/config.rs index ca79f08..35f48a8 100644 --- a/src/commands/config.rs +++ b/src/commands/config.rs @@ -25,7 +25,7 @@ pub fn config_set(args: ConfigSetArgs) { std::process::exit(1); } - write_option_in_cat(category.unwrap(), name, value); + let _ = write_option_in_cat(category.unwrap(), name, value); } @@ -34,7 +34,7 @@ pub fn find_option_in_cat(category: &str, option: &str) -> Option { config.push("config"); let mut in_target_category = false; - if let Ok(mut lines) = read::read_lines(config) { + if let Ok(lines) = read::read_lines(config) { for line in lines { if let Ok(line) = line { @@ -128,7 +128,7 @@ pub fn write_option_in_cat(category: &str, option: &str, value: &str) -> io::Res } pub fn add_remote(name: &str, url: &str) -> io::Result<()> { - let mut config = path::config(); + let config = path::config(); // check if there is already a remote with this name if get_remote(name).is_some() @@ -192,38 +192,3 @@ pub fn get_all_remote() -> Vec<(String, String)> { pub fn get_core(name: &str) -> Option { find_option_in_cat("core", name) } - -pub fn add_core(name: &str, value: &str) -> io::Result<()> { - let mut config = path::nextsync(); - config.push("config"); - - let mut file = OpenOptions::new() - .read(true) - .write(true) - .create(true) - .append(true) - .open(config)?; - - writeln!(file, "[core]")?; - writeln!(file, "\t{} = {}", name, value)?; - - Ok(()) -} - -pub fn get(var: &str) -> Option { - let mut config = path::config(); - - if let Ok(lines) = read::read_lines(config) { - for line in lines { - if let Ok(l) = line { - if l.starts_with(var) { - let (_, val) = l.split_once(" ").unwrap(); - return Some(val.to_owned()); - } - } - } - } - None -} - - diff --git a/src/commands/init.rs b/src/commands/init.rs index ea96338..e0dee36 100644 --- a/src/commands/init.rs +++ b/src/commands/init.rs @@ -12,6 +12,7 @@ pub fn init() { None => env::current_dir().unwrap(), }; + // todo // check if dir is empty // if let Ok(entries) = read_folder(path.clone()) { // if entries.len() != 0 { @@ -58,6 +59,7 @@ pub fn init() { Err(_) => println!("Error: cannot create index"), } + // todo path.pop(); path.pop(); path.push(".nextsyncignore"); diff --git a/src/commands/push/push_factory.rs b/src/commands/push/push_factory.rs index 8be4963..9765e15 100644 --- a/src/commands/push/push_factory.rs +++ b/src/commands/push/push_factory.rs @@ -1,4 +1,3 @@ -use std::error::Error; use std::path::PathBuf; use std::io; use crate::commands::status::{State, LocalObj}; diff --git a/src/store/object/blob.rs b/src/store/object/blob.rs index 9593fb9..202ae0a 100644 --- a/src/store/object/blob.rs +++ b/src/store/object/blob.rs @@ -4,11 +4,10 @@ use std::io::Write; use std::fs::OpenOptions; use std::path::PathBuf; use std::time::SystemTime; -use crate::commands::status::{State}; +use crate::commands::status::State; use crate::utils::into::IntoPathBuf; use crate::utils::{path, read}; -use crate::store::head; -use crate::store::object::{update_dates, add_node, rm_node}; +use crate::store::object::update_dates; use crate::store::object::object::ObjMethods; use crate::store::object::object::Obj; diff --git a/src/store/object/tree.rs b/src/store/object/tree.rs index 6c0568c..d55de4e 100644 --- a/src/store/object/tree.rs +++ b/src/store/object/tree.rs @@ -1,10 +1,9 @@ use crate::utils::into::IntoPathBuf; use crate::store::object::object::Obj; -use std::path::PathBuf; use crate::store::object::update_dates; use crate::store::object::object::ObjMethods; use std::fs::{self, File, OpenOptions}; -use std::io::{self, BufRead, BufReader, Write, Lines}; +use std::io::{self, BufRead, BufReader, Write}; pub struct Tree { pub obj: Obj, diff --git a/src/subcommands/clone.rs b/src/subcommands/clone.rs index 23e7d92..81ce2f2 100644 --- a/src/subcommands/clone.rs +++ b/src/subcommands/clone.rs @@ -1,22 +1,18 @@ use clap::{App, Arg, SubCommand, ArgMatches}; -use textwrap::{fill, Options}; +// use textwrap::{fill, Options}; -use crate::commands::clone::{self, CloneArgs}; +use crate::commands::clone::CloneArgs; use crate::global; use crate::commands; -fn sized_str<'a>(content: &'a str) -> &'a str { - fill(content, Options::new(70).width).as_str(); - "ok" -} - -fn test() -> String { - String::from("ok") -} +// fn sized_str<'a>(content: &'a str) -> &'a str { +// fill(content, Options::new(70).width).as_str(); +// "ok" +// } pub fn create() -> App<'static, 'static> { - let remote_desc = sized_str(&format!("The repository to clone from. See the NEXTSYNC URLS section below for more information on specifying repositories.")); - let depth_desc = sized_str(&format!("Depth of the recursive fetch of object properties. This value should be lower when there are a lot of files per directory and higher when there are a lot of subdirectories with fewer files. (Default: {})", clone::DEPTH)); + // let remote_desc = sized_str(&format!("The repository to clone from. See the NEXTSYNC URLS section below for more information on specifying repositories.")); + // let depth_desc = sized_str(&format!("Depth of the recursive fetch of object properties. This value should be lower when there are a lot of files per directory and higher when there are a lot of subdirectories with fewer files. (Default: {})", clone::DEPTH)); SubCommand::with_name("clone") .arg( Arg::with_name("remote") diff --git a/tests/pull.rs b/tests/pull.rs index a06846f..6e7fccb 100644 --- a/tests/pull.rs +++ b/tests/pull.rs @@ -41,5 +41,4 @@ mod pull_tests { client.clean(); server.clean(); } - } diff --git a/tests/utils/client.rs b/tests/utils/client.rs index 170f643..8b2525f 100644 --- a/tests/utils/client.rs +++ b/tests/utils/client.rs @@ -1,12 +1,13 @@ use std::str; use std::process::{Command, Output}; use std::fs::{self, File}; -use std::io::{Write, BufReader, BufRead}; +use std::io::Write; use std::env; use std::path::PathBuf; use super::files_utils::has_files; +#[cfg(test)] pub struct ClientTest { user: String, // the nextcloud user volume: String, // temp dir for the test @@ -14,6 +15,7 @@ pub struct ClientTest { exe_path: PathBuf, // absolute path of nextsync executable } +#[cfg(test)] impl ClientTest { pub fn new(id: String) -> Self { // create a directory in /tmp with the given id diff --git a/tests/utils/files_utils.rs b/tests/utils/files_utils.rs index 730b73f..b246257 100644 --- a/tests/utils/files_utils.rs +++ b/tests/utils/files_utils.rs @@ -1,7 +1,8 @@ -use std::io::{BufReader, BufRead, Write}; -use std::fs::{File}; +use std::io::{BufReader, BufRead}; +use std::fs::File; use std::path::PathBuf; +#[cfg(test)] pub fn has_files(full_path: PathBuf, file: &str, content: &str, test_id: String) -> bool { if !full_path.exists() { diff --git a/tests/utils/server.rs b/tests/utils/server.rs index bf96373..422d858 100644 --- a/tests/utils/server.rs +++ b/tests/utils/server.rs @@ -1,7 +1,7 @@ use std::process::Command; use std::os::unix::fs::PermissionsExt; use std::fs::{self, File, Permissions}; -use std::io::{BufReader, BufRead, Write}; +use std::io::Write; use std::env; use std::path::PathBuf; diff --git a/tests/utils/status_utils.rs b/tests/utils/status_utils.rs index e9cbf55..4058b6c 100644 --- a/tests/utils/status_utils.rs +++ b/tests/utils/status_utils.rs @@ -1,4 +1,5 @@ +#[cfg(test)] pub fn lines_should_not_contains(lines: Vec, str: &str) { for line in lines { if line.find(str).is_some() { diff --git a/tests/utils/utils.rs b/tests/utils/utils.rs index 80b931d..0988e7f 100644 --- a/tests/utils/utils.rs +++ b/tests/utils/utils.rs @@ -1,5 +1,6 @@ use rand::{distributions::Alphanumeric, Rng}; +#[cfg(test)] pub fn get_random_test_id() -> String { let mut id: String = rand::thread_rng() .sample_iter(&Alphanumeric)