feat: push deletion
This commit is contained in:
parent
4504b98112
commit
939b6f2fe3
@ -73,9 +73,16 @@ pub trait PushChange {
|
||||
};
|
||||
|
||||
// check if remote is newest
|
||||
let last_sync_ts = Blob::from_path(obj.path.clone())
|
||||
let last_sync_ts = {
|
||||
if obj.otype == String::from("blob") {
|
||||
Blob::from_path(obj.path.clone())
|
||||
.saved_remote_ts()
|
||||
.parse::<i64>().unwrap();
|
||||
.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)?;
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
mod utils;
|
||||
use utils::{utils::*, status_utils::*, server::ServerTest, client::ClientTest};
|
||||
|
||||
@ -151,7 +150,6 @@ mod push_tests {
|
||||
// remove it
|
||||
let _ = client.remove_file("file1");
|
||||
client.run_cmd_ok("add file1");
|
||||
dbg!(client.get_status());
|
||||
client.run_cmd_ok("push");
|
||||
|
||||
// tests
|
||||
@ -161,4 +159,27 @@ mod push_tests {
|
||||
client.clean();
|
||||
server.clean();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn push_dir_deletion() {
|
||||
let (mut client, mut server) = init_test();
|
||||
|
||||
// push dir and file2
|
||||
let _ = client.add_dir("dir");
|
||||
let _ = client.add_file("dir/file2", "bar");
|
||||
client.run_cmd_ok("add dir");
|
||||
client.run_cmd_ok("push");
|
||||
|
||||
// tests
|
||||
assert!(server.has_file("dir/file2", "bar"));
|
||||
|
||||
// push deletion
|
||||
let _ = client.remove_dir("dir");
|
||||
client.run_cmd_ok("add dir");
|
||||
client.run_cmd_ok("push");
|
||||
assert!(server.has_not_dir("dir"));
|
||||
|
||||
client.clean();
|
||||
server.clean();
|
||||
}
|
||||
}
|
||||
|
@ -104,6 +104,14 @@ impl ClientTest {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn remove_dir(&mut self, name: &str) -> std::io::Result<()> {
|
||||
let mut path = self.volume.clone();
|
||||
path.push_str("/");
|
||||
path.push_str(name);
|
||||
fs::remove_dir_all(path)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn has_file(&mut self, file: &str, content: &str) -> bool {
|
||||
let full_path = PathBuf::from(self.volume.clone()).join(file);
|
||||
|
||||
|
@ -36,3 +36,15 @@ pub fn has_not_file(full_path: PathBuf, file: &str, test_id: String) -> bool
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn has_not_dir(full_path: PathBuf, dir: &str, test_id: String) -> bool
|
||||
{
|
||||
if full_path.exists() {
|
||||
println!("id: {}", test_id.clone());
|
||||
eprintln!("Dir '{}' exists but it shouldn't", dir);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -113,5 +113,11 @@ impl ServerTest {
|
||||
let full_path = self.volume.clone().join(file);
|
||||
files_utils::has_not_file(full_path, file, self.test_id.clone())
|
||||
}
|
||||
|
||||
pub fn has_not_dir(&mut self, dir: &str) -> bool {
|
||||
let full_path = self.volume.clone().join(dir);
|
||||
dbg!(full_path.clone());
|
||||
files_utils::has_not_file(full_path, dir, self.test_id.clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user