push copy file
This commit is contained in:
@@ -12,6 +12,7 @@ pub mod rm_dir;
|
||||
pub mod deleted;
|
||||
pub mod modified;
|
||||
pub mod moved;
|
||||
pub mod copied;
|
||||
|
||||
pub fn push() {
|
||||
// todo err when pushing new folder
|
||||
|
||||
83
src/commands/push/copied.rs
Normal file
83
src/commands/push/copied.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
use std::path::PathBuf;
|
||||
use std::io;
|
||||
use crate::services::api::ApiError;
|
||||
use crate::services::r#copy::Copy;
|
||||
use crate::services::req_props::ReqProps;
|
||||
use crate::commands::status::LocalObj;
|
||||
use crate::commands::push::push_factory::{PushState, PushChange, PushFlowState};
|
||||
use crate::store::object::blob::Blob;
|
||||
use crate::utils::path::path_buf_to_string;
|
||||
|
||||
pub struct Copied {
|
||||
pub obj: LocalObj,
|
||||
}
|
||||
|
||||
impl PushChange for Copied {
|
||||
fn can_push(&self, whitelist: &mut Option<PathBuf>) -> PushState {
|
||||
match self.flow(&self.obj, whitelist.clone()) {
|
||||
PushFlowState::Whitelisted => PushState::Done,
|
||||
PushFlowState::NotOnRemote => PushState::Valid,
|
||||
PushFlowState::RemoteIsNewer => PushState::Conflict,
|
||||
PushFlowState::LocalIsNewer => PushState::Conflict,
|
||||
PushFlowState::Error => PushState::Error,
|
||||
}
|
||||
}
|
||||
|
||||
fn push(&self) -> io::Result<()> {
|
||||
let obj = &self.obj;
|
||||
let res = Copy::new()
|
||||
.set_url(
|
||||
&path_buf_to_string(obj.path_from.clone().unwrap()),
|
||||
obj.path.to_str().unwrap())
|
||||
.send_with_err();
|
||||
|
||||
match res {
|
||||
Err(ApiError::IncorrectRequest(err)) => {
|
||||
eprintln!("fatal: error copying file {}: {}", obj.name, err.status());
|
||||
std::process::exit(1);
|
||||
},
|
||||
Err(ApiError::RequestError(_)) => {
|
||||
eprintln!("fatal: request error copying file {}", obj.name);
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
// create destination blob
|
||||
if let Err(err) = Blob::new(obj.path.clone()).create(&lastmodified.to_string(), false) {
|
||||
eprintln!("err: creating ref of {}: {}", obj.name.clone(), err);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// download file with .distant at the end
|
||||
fn conflict(&self) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ use crate::commands::push::rm_dir::RmDir;
|
||||
use crate::commands::push::deleted::Deleted;
|
||||
use crate::commands::push::modified::Modified;
|
||||
use crate::commands::push::moved::Moved;
|
||||
use crate::commands::push::copied::Copied;
|
||||
use crate::store::object::blob::Blob;
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -93,6 +94,7 @@ impl PushFactory {
|
||||
State::Modified => Box::new(Modified { obj }),
|
||||
State::Deleted => Box::new(Deleted { obj }),
|
||||
State::Moved => Box::new(Moved { obj }),
|
||||
State::Copied => Box::new(Copied { obj }),
|
||||
State::Default => todo!(),
|
||||
_ => todo!(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user