push deleted dir
This commit is contained in:
parent
2a0fe6d1d1
commit
723ceb2655
@ -5,11 +5,10 @@ use crate::commands::push::push_factory::{PushFactory, PushState};
|
|||||||
pub mod push_factory;
|
pub mod push_factory;
|
||||||
pub mod new;
|
pub mod new;
|
||||||
pub mod new_dir;
|
pub mod new_dir;
|
||||||
|
pub mod rm_dir;
|
||||||
pub mod deleted;
|
pub mod deleted;
|
||||||
|
|
||||||
pub fn push() {
|
pub fn push() {
|
||||||
dbg!(status::get_all_staged());
|
|
||||||
|
|
||||||
let remote = match config::get("remote") {
|
let remote = match config::get("remote") {
|
||||||
Some(r) => r,
|
Some(r) => r,
|
||||||
None => {
|
None => {
|
||||||
@ -22,7 +21,7 @@ pub fn push() {
|
|||||||
let staged_objs = status::get_all_staged();
|
let staged_objs = status::get_all_staged();
|
||||||
|
|
||||||
// path that certify that all its children can be push whithout hesistation
|
// path that certify that all its children can be push whithout hesistation
|
||||||
// (e.g if remote dir has no changes since last sync all children
|
// (e.g. if remote dir has no changes since last sync all children
|
||||||
// can be pushed without verification)
|
// can be pushed without verification)
|
||||||
let mut whitelist: Option<PathBuf> = None;
|
let mut whitelist: Option<PathBuf> = None;
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ use crate::store::object;
|
|||||||
use crate::services::req_props::{ObjProps, ReqProps};
|
use crate::services::req_props::{ObjProps, ReqProps};
|
||||||
use crate::commands::push::new::New;
|
use crate::commands::push::new::New;
|
||||||
use crate::commands::push::new_dir::NewDir;
|
use crate::commands::push::new_dir::NewDir;
|
||||||
|
use crate::commands::push::rm_dir::RmDir;
|
||||||
use crate::commands::push::deleted::Deleted;
|
use crate::commands::push::deleted::Deleted;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -103,7 +104,7 @@ impl PushFactory {
|
|||||||
State::New => Box::new(NewDir { obj }),
|
State::New => Box::new(NewDir { obj }),
|
||||||
State::Renamed => todo!(),
|
State::Renamed => todo!(),
|
||||||
State::Modified => todo!(),
|
State::Modified => todo!(),
|
||||||
State::Deleted => todo!(),
|
State::Deleted => Box::new(RmDir { obj }),
|
||||||
State::Default => todo!(),
|
State::Default => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
55
src/commands/push/rm_dir.rs
Normal file
55
src/commands/push/rm_dir.rs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
use crate::services::api::ApiError;
|
||||||
|
use crate::services::delete_path::DeletePath;
|
||||||
|
use crate::store::index;
|
||||||
|
use crate::store::object::tree;
|
||||||
|
use crate::commands::status::LocalObj;
|
||||||
|
use crate::commands::push::push_factory::{PushState, PushChange, PushFlowState};
|
||||||
|
|
||||||
|
pub struct RmDir {
|
||||||
|
pub obj: LocalObj
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PushChange for RmDir {
|
||||||
|
fn can_push(&self, whitelist: &mut Option<PathBuf>) -> PushState {
|
||||||
|
match self.flow(&self.obj, whitelist.clone()) {
|
||||||
|
PushFlowState::Whitelisted => PushState::Done,
|
||||||
|
PushFlowState::NotOnRemote => {
|
||||||
|
*whitelist = Some(self.obj.path.clone());
|
||||||
|
PushState::Done
|
||||||
|
},
|
||||||
|
PushFlowState::RemoteIsNewer => PushState::Conflict,
|
||||||
|
PushFlowState::LocalIsNewer => {
|
||||||
|
*whitelist = Some(self.obj.path.clone());
|
||||||
|
PushState::Valid
|
||||||
|
},
|
||||||
|
PushFlowState::Error => PushState::Error,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn push(&self) {
|
||||||
|
let obj = &self.obj;
|
||||||
|
let res = DeletePath::new()
|
||||||
|
.set_url(obj.path.to_str().unwrap())
|
||||||
|
.send_with_err();
|
||||||
|
|
||||||
|
match res {
|
||||||
|
Err(ApiError::IncorrectRequest(err)) => {
|
||||||
|
eprintln!("fatal: error deleting dir {}: {}", obj.name, err.status());
|
||||||
|
std::process::exit(1);
|
||||||
|
},
|
||||||
|
Err(ApiError::RequestError(_)) => {
|
||||||
|
eprintln!("fatal: request error deleting dir {}", obj.name);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
// update tree
|
||||||
|
tree::rm(&obj.path.clone());
|
||||||
|
// remove index
|
||||||
|
index::rm_line(obj.path.to_str().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn conflict(&self) {}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user