fix(tests): fix testsuite allow to pass push

This commit is contained in:
grimhilt
2024-03-16 23:57:01 +01:00
parent 7180647d26
commit a1b9cde71a
10 changed files with 60 additions and 48 deletions

View File

@@ -13,15 +13,15 @@ pub fn init() {
};
// check if dir is empty
if let Ok(entries) = read_folder(path.clone()) {
if entries.len() != 0 {
eprintln!("fatal: destination path '{}' already exists and is not an empty directory.", path.display());
std::process::exit(1);
}
} else {
eprintln!("fatal: cannot open the destination directory");
std::process::exit(1);
}
// if let Ok(entries) = read_folder(path.clone()) {
// if entries.len() != 0 {
// eprintln!("fatal: destination path '{}' already exists and is not an empty directory.", path.display());
// std::process::exit(1);
// }
// } else {
// eprintln!("fatal: cannot open the destination directory");
// std::process::exit(1);
// }
let builder = DirBuilder::new();

View File

@@ -16,10 +16,10 @@ pub fn pull() {
.strip_prefix(path::repo_root()).unwrap().to_path_buf();
let (folders, files) = get_diff(relative_p);
let ref_p = path::nextsync();
let root = path::repo_root();
for folder in folders {
let p = ref_p.clone().join(PathBuf::from(folder.relative_s.unwrap()));
let p = root.clone().join(PathBuf::from(folder.relative_s.unwrap()));
if !p.exists() {
// create folder
if let Err(err) = DirBuilder::new().recursive(true).create(p.clone()) {
@@ -27,9 +27,9 @@ pub fn pull() {
}
// add tree
let path_folder = p.strip_prefix(ref_p.clone()).unwrap();
let path_folder = p.strip_prefix(root.clone()).unwrap();
let lastmodified = folder.lastmodified.unwrap().timestamp_millis();
if let Err(err) = Tree::from_path(path_folder.clone()).create(&lastmodified.to_string(), false) {
if let Err(err) = Tree::from_path(path_folder).create(&lastmodified.to_string(), false) {
eprintln!("err: saving ref of {} ({})", path_folder.display(), err);
}
}
@@ -39,13 +39,11 @@ pub fn pull() {
.set_api_props(get_api_props())
.set_files(files)
.should_log()
.download(ref_p.clone(), Some(&update_blob));
.download(root, Some(&update_blob));
// todo look if need to download or update
}
fn update_blob(obj: ObjProps) {
// todo update blob
return;
let relative_s = &obj.clone().relative_s.unwrap();
let relative_p = PathBuf::from(&relative_s);
let lastmodified = obj.clone().lastmodified.unwrap().timestamp_millis();

View File

@@ -39,11 +39,9 @@ pub fn push() {
let mut whitelist: Option<PathBuf> = None;
for obj in staged_objs {
dbg!(obj.clone());
if obj.otype == String::from("tree") {
let push_factory = PushFactory.new_dir(obj.clone());
let res = push_factory.can_push(&mut whitelist);
dbg!(&res);
match res {
PushState::Valid => {
match push_factory.push() {

View File

@@ -24,7 +24,7 @@ pub fn remote_diff() {
pub fn get_diff(path: PathBuf) -> (Vec<ObjProps>, Vec<ObjProps>) {
let depth = "2"; // todo opti
let depth = "6"; // todo opti
let api_props = get_api_props();
enumerate_remote(
@@ -55,6 +55,7 @@ fn req(api_props: &ApiProps, depth: &str, relative_s: &str) -> Result<Vec<ObjPro
.set_request(relative_s, &api_props)
.set_depth(depth)
.gethref()
.getcontentlength() // todo opti
.getlastmodified()
.send_req_multiple()
}

View File

@@ -93,6 +93,7 @@ impl Downloader {
let mut total_size = 0;
let nb_objs = self.files.len();
// set the full size of the download
self.files
.iter()
.for_each(|f|
@@ -111,11 +112,7 @@ impl Downloader {
let should_use_stream = {
if let Some(size) = file.contentlength {
if size > SIZE_TO_STREAM {
true
} else {
false
}
size > SIZE_TO_STREAM
} else {
false
}

View File

@@ -111,6 +111,4 @@ impl Tree {
Ok(())
}
// create
}

View File

@@ -20,6 +20,7 @@ pub fn enumerate_remote(
let mut deleted: Vec<PathBuf> = vec![];
let mut files: Vec<ObjProps> = vec![];
let mut objs_hashmap: HashMap<String, Vec<String>> = HashMap::new();
objs_hashmap.insert(
options.relative_s.clone().unwrap_or(String::new()),
Vec::new());
@@ -53,7 +54,11 @@ pub fn enumerate_remote(
};
// separate folders and files in response
let d = options.depth.clone().unwrap_or("0".to_owned()).parse::<u16>().unwrap();
let d = options.depth.clone()
.unwrap_or("0".to_owned())
.parse::<u16>()
.unwrap();
// first element is not used as it is the fetched folder
if let Some(should_skip_fct) = should_skip.clone() {
iter_with_skip_fct(
@@ -82,6 +87,7 @@ pub fn enumerate_remote(
&mut all_folders);
}
}
// go through all folders not checked for deletion before
// as they were empty
if let Some(_) = should_skip.clone() {
@@ -90,18 +96,13 @@ pub fn enumerate_remote(
objs_hashmap.remove(&key);
}
}
dbg!(deleted);
dbg!(objs_hashmap);
(all_folders, files)
}
fn calc_depth(obj: &ObjProps) -> u16 {
calc_depth_string(obj.relative_s.clone().unwrap_or(String::new()))
}
fn calc_depth_string(s: String) -> u16 {
s.split("/").count() as u16
let path = obj.relative_s.clone().unwrap_or(String::new());
path.split("/").count() as u16
}
fn iter_with_skip_fct(
@@ -121,7 +122,6 @@ fn iter_with_skip_fct(
let current_depth = calc_depth(object);
if object.is_dir() {
// add folder to parent folder only if exists
let mut r_path = PathBuf::from(object.relative_s.clone().unwrap());
r_path.pop();