use PathBuf in obj instead of &Path and get lastmodified when pushing changes
This commit is contained in:
parent
5ccce48381
commit
ddf2169950
@ -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<ObjProps>, 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);
|
||||
|
@ -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!(),
|
||||
};
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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());
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -92,11 +92,12 @@ fn get_staged(new_objs_h: &mut HashMap<String, LocalObj>, 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
|
||||
|
@ -2,4 +2,4 @@ pub mod path;
|
||||
pub mod read;
|
||||
pub mod nextsyncignore;
|
||||
pub mod api;
|
||||
pub mod time;
|
||||
pub mod time;
|
||||
|
Loading…
Reference in New Issue
Block a user