Skip to content
Snippets Groups Projects
Commit 797218b2 authored by nicolas's avatar nicolas
Browse files

src/checkout.rs: usage of --patterns-from instead of exclude-from option for...

src/checkout.rs: usage of --patterns-from instead of exclude-from option for borg + changes in get_entries_to_remove function
parent 33703cac
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ pub fn silent_commit(compression: String, mut commit_id: String, update: bool) {
}
let mut margs: Vec<&str> = vec!["create", "--compression", &compression];
if has_ignore {
margs.push("--exclude-from");
margs.push("--patterns-from");
margs.push(borgignore.to_str().unwrap());
}
let cmd_part = format!("{}::{}", borg_folder.to_str().unwrap(), commit_id);
......@@ -41,7 +41,7 @@ pub fn is_diff(commit1: &str, commit2: &str, borg_folder: &PathBuf,
let cmd = match has_ignore {
false => format!("borg diff {} {}", archive1, commit2),
true => format!(
"borg diff --exclude-from {} {} {}",
"borg diff --patterns-from {} {} {}",
borgignore.to_str().unwrap(),
archive1,
commit2
......@@ -165,7 +165,7 @@ pub fn checkout(mode: &str) {
};
let progress_part = match has_ignore {
false => String::from("--progress"),
true => format!("--progress --exclude-from {}", borgignore.to_str().unwrap()),
true => format!("--progress --patterns-from {}", borgignore.to_str().unwrap()),
};
let cmd = format!(
"borg extract {} {}::{}",
......@@ -208,13 +208,29 @@ mod remove_results {
/// The list of paths to keep
fn get_entries_to_remove(results: &PathBuf, borgignore: &PathBuf, project_dir: &PathBuf) -> Vec<PathBuf> {
let content = fs::read_to_string(borgignore).unwrap();
let mut content = content.lines().map(|x| {
format!("!{}", x)
let content = content.lines().map(|x| {
if x.starts_with("- ") {
x.replace("- ", "!")
} else if x.starts_with("+ ") {
x.replace("+ ", "")
} else {
eprintln!("Error in .borgignore: {} should begin by '+ ' or '- '", x);
exit(81);
}
}).collect::<Vec<_>>();
let mut econtent: Vec<String> = Vec::new();
let mut kcontent: Vec<String> = Vec::new();
for line in content {
if line.starts_with("!") {
econtent.push(line);
} else {
kcontent.push(line);
}
}
let mut ctmp = vec![format!("{}/**", results.to_str().unwrap())];
ctmp.append(&mut content);
ctmp.append(&mut econtent);
let ncontent = ctmp.iter().map(|x| {x.as_str()}).collect::<Vec<_>>();
let walker = globwalk::GlobWalkerBuilder::from_patterns(
let mut walker = globwalk::GlobWalkerBuilder::from_patterns(
project_dir,
&ncontent,
)
......@@ -226,6 +242,19 @@ mod remove_results {
.filter_map(Result::ok)
.map(|x| x.path().to_path_buf())
.collect::<Vec<_>>();
let walker2 = globwalk::GlobWalkerBuilder::from_patterns(
project_dir,
&kcontent,
)
.max_depth(100)
.follow_links(false)
.build()
.unwrap()
.into_iter()
.filter_map(Result::ok)
.map(|x| x.path().to_path_buf())
.collect::<Vec<_>>();
walker.extend(walker2);
walker
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment