push deleted
This commit is contained in:
parent
675b650200
commit
a1aeb65600
@ -1,46 +1,24 @@
|
|||||||
|
use std::path::Path;
|
||||||
use crate::services::api::ApiError;
|
use crate::services::api::ApiError;
|
||||||
use crate::services::req_props::ReqProps;
|
use crate::services::req_props::ReqProps;
|
||||||
use crate::services::delete_path::DeletePath;
|
use crate::services::delete_path::DeletePath;
|
||||||
use crate::store::index;
|
use crate::store::index;
|
||||||
use crate::store::object::rm_blob;
|
use crate::store::object::blob;
|
||||||
use crate::commands::status::Obj;
|
use crate::commands::status::LocalObj;
|
||||||
use crate::commands::push::push_factory::{PushState, PushChange};
|
use crate::commands::push::push_factory::{PushState, PushChange, PushFlowState};
|
||||||
|
|
||||||
pub struct Deleted {
|
pub struct Deleted {
|
||||||
pub obj: Obj,
|
pub obj: LocalObj
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PushChange for Deleted {
|
impl PushChange for Deleted {
|
||||||
fn can_push(&self) -> PushState {
|
fn can_push(&self, whitelist: Option<&Path>) -> PushState {
|
||||||
// check if exist on server
|
match self.flow(&self.obj, whitelist) {
|
||||||
let res = ReqProps::new()
|
PushFlowState::Whitelisted => PushState::Done,
|
||||||
.set_url(&self.obj.path.to_str().unwrap())
|
PushFlowState::NotOnRemote => PushState::Done,
|
||||||
.getlastmodified()
|
PushFlowState::RemoteIsNewer => PushState::Conflict,
|
||||||
.send_with_err();
|
PushFlowState::LocalIsNewer => PushState::Valid,
|
||||||
|
PushFlowState::Error => PushState::Error,
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,8 +41,12 @@ impl PushChange for Deleted {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update tree
|
// update tree
|
||||||
rm_blob(&obj.path.clone());
|
blob::rm(&obj.path.clone());
|
||||||
// remove index
|
// remove index
|
||||||
index::rm_line(obj.path.to_str().unwrap());
|
index::rm_line(obj.path.to_str().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn conflict(&self) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use crate::services::api::ApiError;
|
use crate::services::api::ApiError;
|
||||||
use crate::services::req_props::ReqProps;
|
|
||||||
use crate::services::upload_file::UploadFile;
|
use crate::services::upload_file::UploadFile;
|
||||||
use crate::store::index;
|
use crate::store::index;
|
||||||
use crate::store::object::add_blob;
|
use crate::store::object::blob;
|
||||||
use crate::commands::status::LocalObj;
|
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 struct New {
|
||||||
pub obj: LocalObj,
|
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) {
|
fn push(&self) {
|
||||||
let obj = &self.obj;
|
let obj = &self.obj;
|
||||||
let res = UploadFile::new()
|
let res = UploadFile::new()
|
||||||
@ -51,9 +41,14 @@ impl PushChange for New {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update tree
|
// update tree
|
||||||
add_blob(&obj.path.clone(), "todo_date");
|
blob::add(&obj.path.clone(), "todo_date");
|
||||||
|
|
||||||
// remove index
|
// remove index
|
||||||
index::rm_line(obj.path.to_str().unwrap());
|
index::rm_line(obj.path.to_str().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// download file with .distant at the end
|
||||||
|
fn conflict(&self) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user