From f56dcd30b83b650e360e61f4d4b0c22d94c28cda Mon Sep 17 00:00:00 2001 From: grimhilt Date: Sun, 2 Jul 2023 19:04:45 +0200 Subject: [PATCH] cleaning all warnings --- src/commands/push.rs | 23 ++++++++++++++++++----- src/commands/push/deleted.rs | 12 ++++++++---- src/commands/push/new.rs | 11 +++++++---- src/commands/push/new_dir.rs | 12 +++++++----- src/commands/push/push_factory.rs | 14 +++----------- src/commands/push/rm_dir.rs | 10 +++++++--- src/commands/status.rs | 8 +++----- src/services/req_props.rs | 2 +- src/store/object.rs | 7 ++++--- src/store/object/blob.rs | 2 +- src/store/object/tree.rs | 11 ++++++----- 11 files changed, 65 insertions(+), 47 deletions(-) diff --git a/src/commands/push.rs b/src/commands/push.rs index 53b57e6..267feee 100644 --- a/src/commands/push.rs +++ b/src/commands/push.rs @@ -9,7 +9,8 @@ pub mod rm_dir; pub mod deleted; pub fn push() { - let remote = match config::get("remote") { + // todo + let _remote = match config::get("remote") { Some(r) => r, None => { eprintln!("fatal: no remote set in configuration"); @@ -27,11 +28,17 @@ pub fn push() { for obj in staged_objs { if obj.otype == String::from("tree") { - dbg!(("folder", obj.clone())); let push_factory = PushFactory.new_dir(obj.clone()); let res = push_factory.can_push(&mut whitelist); match res { - PushState::Valid => push_factory.push(), + PushState::Valid => { + match push_factory.push() { + Ok(()) => (), + Err(err) => { + eprintln!("err: pushing {}: {}", obj.name, err); + } + } + }, PushState::Done => (), PushState::Conflict => { println!("CONFLICT: {}", obj.clone().name); @@ -40,10 +47,16 @@ pub fn push() { }; } else { - dbg!(("file", obj.clone())); let push_factory = PushFactory.new(obj.clone()); match push_factory.can_push(&mut whitelist) { - PushState::Valid => push_factory.push(), + PushState::Valid => { + match push_factory.push() { + Ok(()) => (), + Err(err) => { + eprintln!("err: pushing {}: {}", obj.name, err); + } + } + }, PushState::Done => (), PushState::Conflict => { // download file diff --git a/src/commands/push/deleted.rs b/src/commands/push/deleted.rs index cc41211..44c0eed 100644 --- a/src/commands/push/deleted.rs +++ b/src/commands/push/deleted.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; +use std::io; use crate::services::api::ApiError; -use crate::services::req_props::ReqProps; use crate::services::delete_path::DeletePath; use crate::store::index; use crate::store::object::blob; @@ -22,7 +22,7 @@ impl PushChange for Deleted { } } - fn push(&self) { + fn push(&self) -> io::Result<()> { let obj = &self.obj; let res = DeletePath::new() .set_url(obj.path.to_str().unwrap()) @@ -41,9 +41,13 @@ impl PushChange for Deleted { } // update tree - blob::rm(obj.path.clone()); + // todo date + blob::rm(obj.path.clone())?; + // remove index - index::rm_line(obj.path.to_str().unwrap()); + index::rm_line(obj.path.to_str().unwrap())?; + + Ok(()) } fn conflict(&self) { diff --git a/src/commands/push/new.rs b/src/commands/push/new.rs index c4b62d0..9b949e4 100644 --- a/src/commands/push/new.rs +++ b/src/commands/push/new.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; +use std::io; use crate::services::api::ApiError; -use crate::services::req_props::{ReqProps, ObjProps}; +use crate::services::req_props::ReqProps; use crate::services::upload_file::UploadFile; use crate::store::index; use crate::store::object::blob; @@ -22,7 +23,7 @@ impl PushChange for New { } } - fn push(&self) { + fn push(&self) -> io::Result<()> { let obj = &self.obj; let res = UploadFile::new() .set_url(obj.path.to_str().unwrap()) @@ -67,10 +68,12 @@ impl PushChange for New { let lastmodified = prop.lastmodified.unwrap().timestamp_millis(); // update blob - blob::add(obj.path.clone(), &lastmodified.to_string()); + blob::add(obj.path.clone(), &lastmodified.to_string())?; // remove index - index::rm_line(obj.path.to_str().unwrap()); + index::rm_line(obj.path.to_str().unwrap())?; + + Ok(()) } // download file with .distant at the end diff --git a/src/commands/push/new_dir.rs b/src/commands/push/new_dir.rs index 2f04f91..a45d527 100644 --- a/src/commands/push/new_dir.rs +++ b/src/commands/push/new_dir.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; +use std::io; use crate::services::api::ApiError; -use crate::services::req_props::{ReqProps, ObjProps}; +use crate::services::req_props::ReqProps; use crate::services::create_folder::CreateFolder; use crate::store::index; use crate::store::object::tree; @@ -28,7 +29,7 @@ impl PushChange for NewDir { } } - fn push(&self) { + fn push(&self) -> io::Result<()> { let obj = &self.obj; let res = CreateFolder::new() .set_url(obj.path.to_str().unwrap()) @@ -71,13 +72,14 @@ impl PushChange for NewDir { }; let lastmodified = prop.lastmodified.unwrap().timestamp_millis(); - dbg!(lastmodified); // update tree - tree::add(obj.path.clone(), &lastmodified.to_string()); + tree::add(obj.path.clone(), &lastmodified.to_string())?; // remove index - index::rm_line(obj.path.to_str().unwrap()); + index::rm_line(obj.path.to_str().unwrap())?; + + Ok(()) } fn conflict(&self) {} diff --git a/src/commands/push/push_factory.rs b/src/commands/push/push_factory.rs index b6c12e8..ee10bf9 100644 --- a/src/commands/push/push_factory.rs +++ b/src/commands/push/push_factory.rs @@ -1,8 +1,9 @@ use std::path::PathBuf; +use std::io; use crate::commands::status::{State, LocalObj}; use crate::services::api::ApiError; use crate::store::object; -use crate::services::req_props::{ObjProps, ReqProps}; +use crate::services::req_props::ReqProps; use crate::commands::push::new::New; use crate::commands::push::new_dir::NewDir; use crate::commands::push::rm_dir::RmDir; @@ -26,18 +27,9 @@ pub enum PushFlowState { pub trait PushChange { fn can_push(&self, whitelist: &mut Option) -> PushState; - fn push(&self); + fn push(&self) -> io::Result<()>; fn conflict(&self); - fn try_push(&self, whitelist: &mut Option) { - match self.can_push(whitelist) { - PushState::Valid => self.push(), - PushState::Conflict => self.conflict(), - PushState::Done => (), - PushState::Error => (), - } - } - fn is_whitelisted(&self, obj: &LocalObj, path: Option) -> bool { match path { Some(p) => obj.path.starts_with(p), diff --git a/src/commands/push/rm_dir.rs b/src/commands/push/rm_dir.rs index 51846b1..429a5e5 100644 --- a/src/commands/push/rm_dir.rs +++ b/src/commands/push/rm_dir.rs @@ -1,4 +1,5 @@ use std::path::PathBuf; +use std::io; use crate::services::api::ApiError; use crate::services::delete_path::DeletePath; use crate::store::index; @@ -27,7 +28,7 @@ impl PushChange for RmDir { } } - fn push(&self) { + fn push(&self) -> io::Result<()> { let obj = &self.obj; let res = DeletePath::new() .set_url(obj.path.to_str().unwrap()) @@ -47,9 +48,12 @@ impl PushChange for RmDir { // update tree // todo update date - tree::rm(obj.path.clone()); + tree::rm(obj.path.clone())?; + // remove index - index::rm_line(obj.path.to_str().unwrap()); + index::rm_line(obj.path.to_str().unwrap())?; + + Ok(()) } fn conflict(&self) {} diff --git a/src/commands/status.rs b/src/commands/status.rs index 23f4f70..d650c18 100644 --- a/src/commands/status.rs +++ b/src/commands/status.rs @@ -1,7 +1,7 @@ use std::fs::File; use std::path::PathBuf; use std::io::{self, Lines, BufReader}; -use std::collections::{HashSet, HashMap}; +use std::collections::HashMap; use crypto::digest::Digest; use crypto::sha1::Sha1; use colored::Colorize; @@ -31,7 +31,7 @@ pub enum State { pub fn status() { let (mut new_objs_hashes, mut del_objs_hashes) = get_diff(); // get copy, modified - let mut staged_objs = get_staged(&mut new_objs_hashes, &mut del_objs_hashes); + let staged_objs = get_staged(&mut new_objs_hashes, &mut del_objs_hashes); let mut objs: Vec = del_objs_hashes.iter().map(|x| { x.1.clone() @@ -41,8 +41,6 @@ pub fn status() { objs.push(elt.clone()); } - dbg!(objs.clone()); - dbg!(staged_objs.clone()); print_status(staged_objs, objs); } @@ -57,7 +55,7 @@ pub struct LocalObj { pub fn get_all_staged() -> Vec { let (mut new_objs_hashes, mut del_objs_hashes) = get_diff(); // get copy, modified - let mut staged_objs = get_staged(&mut new_objs_hashes, &mut del_objs_hashes); + let staged_objs = get_staged(&mut new_objs_hashes, &mut del_objs_hashes); staged_objs.clone() // todo opti getting staged and then finding differences ? diff --git a/src/services/req_props.rs b/src/services/req_props.rs index 71aed71..86f3427 100644 --- a/src/services/req_props.rs +++ b/src/services/req_props.rs @@ -73,7 +73,7 @@ impl ReqProps { self } - pub fn getcontentlenght(&mut self) -> &mut ReqProps { + pub fn _getcontentlenght(&mut self) -> &mut ReqProps { self.xml_balises.push(String::from("getcontentlength")); self.xml_payload.push_str(r#""#); self diff --git a/src/store/object.rs b/src/store/object.rs index af92ba6..10ce3da 100644 --- a/src/store/object.rs +++ b/src/store/object.rs @@ -87,17 +87,19 @@ fn add_node(path: &Path, node: &str) -> io::Result<()> { Ok(()) } -fn update_dates(mut path: PathBuf, date: &str) { +fn update_dates(mut path: PathBuf, date: &str) -> io::Result<()> { let mut obj_p = path::objects(); while path.pop() { let (dir, res) = hash_obj(path.to_str().unwrap()); obj_p.push(dir); obj_p.push(res); - update_date(obj_p.clone(), date.clone()); + update_date(obj_p.clone(), date.clone())?; obj_p.pop(); obj_p.pop(); } + + Ok(()) } pub fn update_date(path: PathBuf, date: &str) -> io::Result<()> { @@ -151,7 +153,6 @@ pub fn get_timestamp(path_s: String) -> Option { let mut obj_p = path::objects(); let (dir, res) = hash_obj(&path_s); - dbg!((dir.clone(), res.clone())); obj_p.push(dir); obj_p.push(res); diff --git a/src/store/object/blob.rs b/src/store/object/blob.rs index 78b4280..4e3dee9 100644 --- a/src/store/object/blob.rs +++ b/src/store/object/blob.rs @@ -22,7 +22,7 @@ pub fn add(path: PathBuf, date: &str) -> io::Result<()> { create_obj(hash, &content)?; // update date for all parent - update_dates(path, date); + update_dates(path, date)?; Ok(()) } diff --git a/src/store/object/tree.rs b/src/store/object/tree.rs index 9fab3c0..0d1903c 100644 --- a/src/store/object/tree.rs +++ b/src/store/object/tree.rs @@ -22,7 +22,7 @@ pub fn add(path: PathBuf, date: &str) -> io::Result<()> { create_obj(hash, &content)?; // update date for all parent - update_dates(path, date); + update_dates(path, date)?; Ok(()) } @@ -34,13 +34,13 @@ pub fn rm(path: PathBuf) -> io::Result<()> { if ftype == String::from("blob") { object::rm(&hash)?; } else { - rm_hash(hash); + rm_hash(hash)?; } } Ok(()) } -fn rm_hash(hash: String) { +fn rm_hash(hash: String) -> io::Result<()> { let mut obj_p = path::objects(); let (dir, res) = hash.split_at(2); obj_p.push(dir); @@ -52,9 +52,9 @@ fn rm_hash(hash: String) { for line in reader { let (ftype, hash, _) = parse_line(line.unwrap()); if ftype == String::from("blob") { - object::rm(&hash); + object::rm(&hash)?; } else { - rm_hash(hash); + rm_hash(hash)?; } } }, @@ -62,6 +62,7 @@ fn rm_hash(hash: String) { eprintln!("error reading tree: {}", err); }, } + Ok(()) } pub fn read(tree: String) -> Option<(String, io::Lines>)> {