feat: push deletion
This commit is contained in:
@@ -73,9 +73,16 @@ pub trait PushChange {
|
||||
};
|
||||
|
||||
// check if remote is newest
|
||||
let last_sync_ts = Blob::from_path(obj.path.clone())
|
||||
.saved_remote_ts()
|
||||
.parse::<i64>().unwrap();
|
||||
let last_sync_ts = {
|
||||
if obj.otype == String::from("blob") {
|
||||
Blob::from_path(obj.path.clone())
|
||||
.saved_remote_ts()
|
||||
.parse::<i64>().unwrap()
|
||||
} else {
|
||||
// todo timestamp on tree
|
||||
99999999999999
|
||||
}
|
||||
};
|
||||
let remote_ts = obj_data.lastmodified.unwrap().timestamp_millis();
|
||||
|
||||
if last_sync_ts < remote_ts {
|
||||
|
||||
@@ -178,8 +178,7 @@ impl ObjMethods for Blob {
|
||||
|
||||
fn rm_node(&mut self) -> io::Result<()> {
|
||||
// remove self object and children object
|
||||
self.rm_node_down();
|
||||
|
||||
let _ = self.rm_node_down();
|
||||
self.obj.rm_node()
|
||||
}
|
||||
|
||||
@@ -246,7 +245,7 @@ impl ObjMethods for Tree {
|
||||
|
||||
fn rm_node(&mut self) -> io::Result<()> {
|
||||
// remove self object and children object
|
||||
self.rm_node_down();
|
||||
let _ = self.rm_node_down();
|
||||
self.obj.rm_node()
|
||||
}
|
||||
|
||||
@@ -336,7 +335,7 @@ impl Obj {
|
||||
pub fn from_line(line: String, base_dir: Option<PathBuf>) -> Box<dyn ObjMethods> {
|
||||
let mut split = line.trim().rsplit(' ');
|
||||
if split.clone().count() != 3 {
|
||||
eprintln!("fatal: invalid object(s)");
|
||||
eprintln!("fatal: invalid object(s) ({})", line.trim());
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ pub struct Tree {
|
||||
is_head: bool,
|
||||
}
|
||||
|
||||
|
||||
impl Tree {
|
||||
pub fn new(obj: Obj) -> Self {
|
||||
Tree {
|
||||
@@ -42,9 +41,10 @@ impl Tree {
|
||||
if let Ok(file) = File::open(self.get_obj_path()) {
|
||||
self.buf_reader = Some(BufReader::new(file));
|
||||
|
||||
// skip first line if is head
|
||||
// skip first line (declaration) if is not head
|
||||
if !self.is_head {
|
||||
self.next();
|
||||
let mut line = String::new();
|
||||
self.buf_reader.as_mut().unwrap().read_line(&mut line);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,11 +99,11 @@ impl Tree {
|
||||
.open(self.get_obj_path())?;
|
||||
|
||||
// update date for all parent
|
||||
if up_parent {
|
||||
if let Err(err) = update_dates(self.get_relative_file_path(), date) {
|
||||
eprintln!("err: updating parent date of {}: {}", self.get_relative_file_path().display(), err);
|
||||
}
|
||||
}
|
||||
// if up_parent {
|
||||
// if let Err(err) = update_dates(self.get_relative_file_path(), date) {
|
||||
// eprintln!("err: updating parent date of {}: {}", self.get_relative_file_path().display(), err);
|
||||
// }
|
||||
// }
|
||||
|
||||
writeln!(file, "{}", content)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user