diff --git a/src/commands/push/deleted.rs b/src/commands/push/deleted.rs index b0325f3..8b2825d 100644 --- a/src/commands/push/deleted.rs +++ b/src/commands/push/deleted.rs @@ -1,46 +1,24 @@ +use std::path::Path; 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::rm_blob; -use crate::commands::status::Obj; -use crate::commands::push::push_factory::{PushState, PushChange}; +use crate::store::object::blob; +use crate::commands::status::LocalObj; +use crate::commands::push::push_factory::{PushState, PushChange, PushFlowState}; pub struct Deleted { - pub obj: Obj, + pub obj: LocalObj } impl PushChange for Deleted { - fn can_push(&self) -> PushState { - // check if exist on server - let res = ReqProps::new() - .set_url(&self.obj.path.to_str().unwrap()) - .getlastmodified() - .send_with_err(); - - let file_infos = match res { - Ok(obj) => Ok(Some(obj)), - Err(ApiError::IncorrectRequest(err)) => { - if err.status() == 404 { - Ok(None) - } else { - Err(()) - } - }, - Err(_) => Err(()), - }; - - if let Ok(infos) = file_infos { - if let Some(inf) = infos { - // file doesn't exist on remote - PushState::Done - } else { - // todo check date - //PushState::Conflict - PushState::Valid - } - } else { - PushState::Error + fn can_push(&self, whitelist: Option<&Path>) -> PushState { + match self.flow(&self.obj, whitelist) { + PushFlowState::Whitelisted => PushState::Done, + PushFlowState::NotOnRemote => PushState::Done, + PushFlowState::RemoteIsNewer => PushState::Conflict, + PushFlowState::LocalIsNewer => PushState::Valid, + PushFlowState::Error => PushState::Error, } } @@ -63,8 +41,12 @@ impl PushChange for Deleted { } // update tree - rm_blob(&obj.path.clone()); + blob::rm(&obj.path.clone()); // remove index index::rm_line(obj.path.to_str().unwrap()); } + + fn conflict(&self) { + + } } diff --git a/src/commands/push/new.rs b/src/commands/push/new.rs index e062aa4..771473c 100644 --- a/src/commands/push/new.rs +++ b/src/commands/push/new.rs @@ -1,11 +1,10 @@ use std::path::Path; use crate::services::api::ApiError; -use crate::services::req_props::ReqProps; use crate::services::upload_file::UploadFile; use crate::store::index; -use crate::store::object::add_blob; +use crate::store::object::blob; use crate::commands::status::LocalObj; -use crate::commands::push::push_factory::{PushState, PushChange, PushFactory, PushFlowState}; +use crate::commands::push::push_factory::{PushState, PushChange, PushFlowState}; pub struct New { pub obj: LocalObj, @@ -22,15 +21,6 @@ impl PushChange for New { } } - fn try_push(&self, whitelist: Option<&Path>) { - match self.can_push(whitelist) { - PushState::Valid => self.push(), - PushState::Conflict => todo!(), //download - PushState::Done => (), - PushState::Error => (), - } - } - fn push(&self) { let obj = &self.obj; let res = UploadFile::new() @@ -51,9 +41,14 @@ impl PushChange for New { } // update tree - add_blob(&obj.path.clone(), "todo_date"); + blob::add(&obj.path.clone(), "todo_date"); // remove index index::rm_line(obj.path.to_str().unwrap()); } + + // download file with .distant at the end + fn conflict(&self) { + todo!() + } }