From 2af028acaedca10aec4a30933d372e010a76c73a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Wed, 26 Sep 2018 20:33:53 +0200 Subject: [PATCH] Add function to check if files are present --- .../benchmark_repository/examples/test.rs | 9 +++++- benchmark-new/benchmark_repository/src/lib.rs | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/benchmark-new/benchmark_repository/examples/test.rs b/benchmark-new/benchmark_repository/examples/test.rs index 52922f955..241443222 100644 --- a/benchmark-new/benchmark_repository/examples/test.rs +++ b/benchmark-new/benchmark_repository/examples/test.rs @@ -40,7 +40,14 @@ fn main() let instance_domain = instance["domain"].as_str().unwrap(); let instance_number = instance["instance"].as_i64().unwrap(); - println!("[{}, {}, {}/{}/{}]", configuration_id, instance_set_id, instance_ipc, instance_domain, instance_number); + let file_name = format!("{}/{}/{}", instance_ipc, instance_domain, instance_number); + + if (benchmark_repository.file_exists(Path::new(&file_name), "test-results")) + { + continue; + } + + println!("to do: [{}, {}, {}/{}/{}]", configuration_id, instance_set_id, instance_ipc, instance_domain, instance_number); } } } diff --git a/benchmark-new/benchmark_repository/src/lib.rs b/benchmark-new/benchmark_repository/src/lib.rs index ca584a85b..f5efc6a18 100644 --- a/benchmark-new/benchmark_repository/src/lib.rs +++ b/benchmark-new/benchmark_repository/src/lib.rs @@ -283,6 +283,36 @@ impl BenchmarkRepository remote.push(&[&push_refspec], Some(&mut push_options)).expect("couldn’t push"); } + pub fn file_exists(&self, file_path: &Path, branch_name: &str) -> bool + { + let tip_reference_name = format!("refs/remotes/origin/{}", branch_name); + let tip_reference = match self.repository.find_reference(&tip_reference_name) + { + Ok(value) => value, + Err(error) => panic!("Could not find reference “{}”: {}", tip_reference_name, error), + }; + + let tree = match tip_reference.peel_to_tree() + { + Ok(value) => value, + Err(error) => panic!("Could not peel reference to tree: {}", error), + }; + + let object_id = match tree.get_path(file_path) + { + Ok(tree_entry) => tree_entry.id(), + Err(error) => return false, + }; + + let blob = match self.repository.find_blob(object_id) + { + Ok(blob) => blob, + Err(error) => return false, + }; + + true + } + pub fn read_file(&self, file_path: &Path, branch_name: &str) -> Option { let tip_reference_name = format!("refs/remotes/origin/{}", branch_name);