diff --git a/src/commands/clone.rs b/src/commands/clone.rs index e0b0c28..11843f9 100644 --- a/src/commands/clone.rs +++ b/src/commands/clone.rs @@ -104,7 +104,7 @@ pub fn clone(remote: Values<'_>) { // add tree let path_folder = p.strip_prefix(ref_path.clone()).unwrap(); let lastmodified = folder.lastmodified.unwrap().timestamp_millis(); - if let Err(err) = tree::add(&path_folder, &lastmodified.to_string()) { + if let Err(err) = tree::add(path_folder.to_path_buf(), &lastmodified.to_string()) { eprintln!("err: saving ref of {} ({})", path_folder.display(), err); } } @@ -134,7 +134,7 @@ fn download_files(ref_p: PathBuf, files: Vec, api_props: &ApiProps) { match res { Ok(()) => { - let relative_p = Path::new(&relative_s); + let relative_p = PathBuf::from(&relative_s); let lastmodified = obj.clone().lastmodified.unwrap().timestamp_millis(); if let Err(err) = blob::add(relative_p, &lastmodified.to_string()) { eprintln!("err: saving ref of {} ({})", relative_s.clone(), err); diff --git a/src/commands/push.rs b/src/commands/push.rs index 5f20241..53b57e6 100644 --- a/src/commands/push.rs +++ b/src/commands/push.rs @@ -29,10 +29,13 @@ pub fn push() { if obj.otype == String::from("tree") { dbg!(("folder", obj.clone())); let push_factory = PushFactory.new_dir(obj.clone()); - let res = match push_factory.can_push(&mut whitelist) { + let res = push_factory.can_push(&mut whitelist); + match res { PushState::Valid => push_factory.push(), PushState::Done => (), - PushState::Conflict => (), + PushState::Conflict => { + println!("CONFLICT: {}", obj.clone().name); + }, _ => todo!(), }; diff --git a/src/commands/push/deleted.rs b/src/commands/push/deleted.rs index 78028a5..cc41211 100644 --- a/src/commands/push/deleted.rs +++ b/src/commands/push/deleted.rs @@ -41,7 +41,7 @@ impl PushChange for Deleted { } // update tree - blob::rm(&obj.path.clone()); + blob::rm(obj.path.clone()); // remove index index::rm_line(obj.path.to_str().unwrap()); } diff --git a/src/commands/push/new.rs b/src/commands/push/new.rs index 029b8ca..c4b62d0 100644 --- a/src/commands/push/new.rs +++ b/src/commands/push/new.rs @@ -1,5 +1,6 @@ use std::path::PathBuf; use crate::services::api::ApiError; +use crate::services::req_props::{ReqProps, ObjProps}; use crate::services::upload_file::UploadFile; use crate::store::index; use crate::store::object::blob; @@ -40,8 +41,33 @@ impl PushChange for New { _ => (), } - // update tree - blob::add(&obj.path.clone(), "todo_date"); + // get lastmodified props to update it + let props = ReqProps::new() + .set_url(obj.path.to_str().unwrap()) + .getlastmodified() + .send_req_single(); + + let prop = match props { + Ok(o) => o, + Err(ApiError::IncorrectRequest(err)) => { + eprintln!("fatal: {}", err.status()); + std::process::exit(1); + }, + Err(ApiError::EmptyError(_)) => { + eprintln!("Failed to get body"); + std::process::exit(1); + } + Err(ApiError::RequestError(err)) => { + eprintln!("fatal: {}", err); + std::process::exit(1); + }, + Err(ApiError::Unexpected(_)) => todo!() + }; + + let lastmodified = prop.lastmodified.unwrap().timestamp_millis(); + + // update blob + blob::add(obj.path.clone(), &lastmodified.to_string()); // remove index index::rm_line(obj.path.to_str().unwrap()); diff --git a/src/commands/push/new_dir.rs b/src/commands/push/new_dir.rs index 20c4b0f..2f04f91 100644 --- a/src/commands/push/new_dir.rs +++ b/src/commands/push/new_dir.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; use crate::services::api::ApiError; -use crate::services::req_props::ReqProps; +use crate::services::req_props::{ReqProps, ObjProps}; use crate::services::create_folder::CreateFolder; use crate::store::index; use crate::store::object::tree; @@ -46,8 +46,35 @@ impl PushChange for NewDir { _ => (), } + + // get lastmodified props to update it + let props = ReqProps::new() + .set_url(obj.path.to_str().unwrap()) + .getlastmodified() + .send_req_single(); + + let prop = match props { + Ok(o) => o, + Err(ApiError::IncorrectRequest(err)) => { + eprintln!("fatal: {}", err.status()); + std::process::exit(1); + }, + Err(ApiError::EmptyError(_)) => { + eprintln!("Failed to get body"); + std::process::exit(1); + } + Err(ApiError::RequestError(err)) => { + eprintln!("fatal: {}", err); + std::process::exit(1); + }, + Err(ApiError::Unexpected(_)) => todo!() + }; + + let lastmodified = prop.lastmodified.unwrap().timestamp_millis(); + dbg!(lastmodified); + // update tree - tree::add(&obj.path.clone(), "todo_date"); + tree::add(obj.path.clone(), &lastmodified.to_string()); // remove index index::rm_line(obj.path.to_str().unwrap()); diff --git a/src/commands/push/rm_dir.rs b/src/commands/push/rm_dir.rs index 69cebb6..51846b1 100644 --- a/src/commands/push/rm_dir.rs +++ b/src/commands/push/rm_dir.rs @@ -46,7 +46,8 @@ impl PushChange for RmDir { } // update tree - tree::rm(&obj.path.clone()); + // todo update date + tree::rm(obj.path.clone()); // remove index index::rm_line(obj.path.to_str().unwrap()); } diff --git a/src/commands/status.rs b/src/commands/status.rs index 3b1f6c3..23f4f70 100644 --- a/src/commands/status.rs +++ b/src/commands/status.rs @@ -92,11 +92,12 @@ fn get_staged(new_objs_h: &mut HashMap, del_objs_h: &mut HashM del_objs_h.remove(&hash); }else { let mut t_path = ref_p.clone(); - t_path.push(PathBuf::from(obj.clone())); + let relative_p = PathBuf::from(obj.clone()); + t_path.push(relative_p.clone()); staged_objs.push(LocalObj { otype: get_otype(t_path.clone()), name: obj.to_string(), - path: t_path.clone(), + path: relative_p.clone(), state: { if t_path.exists() { State::New diff --git a/src/utils.rs b/src/utils.rs index bb81503..f530c31 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,4 +2,4 @@ pub mod path; pub mod read; pub mod nextsyncignore; pub mod api; -pub mod time; \ No newline at end of file +pub mod time;