use PathBuf in obj instead of &Path and get lastmodified when pushing changes

This commit is contained in:
grimhilt 2023-07-02 18:50:33 +02:00
parent 5ccce48381
commit ddf2169950
8 changed files with 71 additions and 13 deletions

View File

@ -104,7 +104,7 @@ pub fn clone(remote: Values<'_>) {
// add tree // add tree
let path_folder = p.strip_prefix(ref_path.clone()).unwrap(); let path_folder = p.strip_prefix(ref_path.clone()).unwrap();
let lastmodified = folder.lastmodified.unwrap().timestamp_millis(); 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); 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 { match res {
Ok(()) => { Ok(()) => {
let relative_p = Path::new(&relative_s); let relative_p = PathBuf::from(&relative_s);
let lastmodified = obj.clone().lastmodified.unwrap().timestamp_millis(); let lastmodified = obj.clone().lastmodified.unwrap().timestamp_millis();
if let Err(err) = blob::add(relative_p, &lastmodified.to_string()) { if let Err(err) = blob::add(relative_p, &lastmodified.to_string()) {
eprintln!("err: saving ref of {} ({})", relative_s.clone(), err); eprintln!("err: saving ref of {} ({})", relative_s.clone(), err);

View File

@ -29,10 +29,13 @@ pub fn push() {
if obj.otype == String::from("tree") { if obj.otype == String::from("tree") {
dbg!(("folder", obj.clone())); dbg!(("folder", obj.clone()));
let push_factory = PushFactory.new_dir(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::Valid => push_factory.push(),
PushState::Done => (), PushState::Done => (),
PushState::Conflict => (), PushState::Conflict => {
println!("CONFLICT: {}", obj.clone().name);
},
_ => todo!(), _ => todo!(),
}; };

View File

@ -41,7 +41,7 @@ impl PushChange for Deleted {
} }
// update tree // update tree
blob::rm(&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());
} }

View File

@ -1,5 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
use crate::services::api::ApiError; use crate::services::api::ApiError;
use crate::services::req_props::{ReqProps, ObjProps};
use crate::services::upload_file::UploadFile; use crate::services::upload_file::UploadFile;
use crate::store::index; use crate::store::index;
use crate::store::object::blob; use crate::store::object::blob;
@ -40,8 +41,33 @@ impl PushChange for New {
_ => (), _ => (),
} }
// update tree // get lastmodified props to update it
blob::add(&obj.path.clone(), "todo_date"); 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 // remove index
index::rm_line(obj.path.to_str().unwrap()); index::rm_line(obj.path.to_str().unwrap());

View File

@ -1,6 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
use crate::services::api::ApiError; 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::services::create_folder::CreateFolder;
use crate::store::index; use crate::store::index;
use crate::store::object::tree; 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 // update tree
tree::add(&obj.path.clone(), "todo_date"); tree::add(obj.path.clone(), &lastmodified.to_string());
// remove index // remove index
index::rm_line(obj.path.to_str().unwrap()); index::rm_line(obj.path.to_str().unwrap());

View File

@ -46,7 +46,8 @@ impl PushChange for RmDir {
} }
// update tree // update tree
tree::rm(&obj.path.clone()); // todo update date
tree::rm(obj.path.clone());
// remove index // remove index
index::rm_line(obj.path.to_str().unwrap()); index::rm_line(obj.path.to_str().unwrap());
} }

View File

@ -92,11 +92,12 @@ fn get_staged(new_objs_h: &mut HashMap<String, LocalObj>, del_objs_h: &mut HashM
del_objs_h.remove(&hash); del_objs_h.remove(&hash);
}else { }else {
let mut t_path = ref_p.clone(); 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 { staged_objs.push(LocalObj {
otype: get_otype(t_path.clone()), otype: get_otype(t_path.clone()),
name: obj.to_string(), name: obj.to_string(),
path: t_path.clone(), path: relative_p.clone(),
state: { state: {
if t_path.exists() { if t_path.exists() {
State::New State::New

View File

@ -2,4 +2,4 @@ pub mod path;
pub mod read; pub mod read;
pub mod nextsyncignore; pub mod nextsyncignore;
pub mod api; pub mod api;
pub mod time; pub mod time;