Skip to content
Snippets Groups Projects
Commit 2c050d31 authored by nfontrod's avatar nfontrod
Browse files

src/commit.rs: add handle for .borgignore file

parent 8acb786a
No related branches found
No related tags found
No related merge requests found
......@@ -53,23 +53,48 @@ pub fn delete_commit(commit: &str, borg_path: &PathBuf) {
}
}
/// Checks if .borgignore file exists in the project folder
///
/// # Arguments:
/// * borg_folder: Path to .borg folder
///
/// # Return:
/// A tuple containing:
/// * A boolean indicating if .borgignore file exits
/// * The path to this borgignore file
fn check_if_borgignore_exists(borg_folder: &PathBuf) -> (bool, PathBuf) {
let mut project_folder = borg_folder.parent().unwrap().to_path_buf();
project_folder.push(".borgignore");
(project_folder.is_file(), project_folder)
}
/// Create a commit of the results folder named as the current git commit id
pub fn commit(compression: String, mut commit_id: String, update: bool) {
let (borg_folder, results_folder) = check_path();
let (has_ignore, borgignore) = check_if_borgignore_exists(&borg_folder);
if commit_id == String::from("") {
commit_id = get_current_commit();
}
if update {
delete_commit(&commit_id, &borg_folder);
}
let mut margs: Vec<&str> = vec![
"create",
"--stats",
"--progress",
"--compression",
&compression,
];
if has_ignore {
margs.push("--exclude-from");
margs.push(borgignore.to_str().unwrap());
}
let cmd_part = format!("{}::{}", borg_folder.to_str().unwrap(), commit_id);
margs.push(&cmd_part);
margs.push(results_folder.to_str().unwrap());
let mut output = Command::new("borg")
.arg("create")
.arg("--stats")
.arg("--progress")
.arg("--compression")
.arg(compression)
.arg(format!("{}::{}", borg_folder.to_str().unwrap(), commit_id))
.arg(results_folder.to_str().unwrap())
.args(margs)
.stdout(Stdio::piped())
.spawn()
.unwrap_or_else(|e| {
......@@ -77,7 +102,7 @@ pub fn commit(compression: String, mut commit_id: String, update: bool) {
exit(8);
});
let ecode = output.wait().expect("error");
match ecode.code().unwrap() {
match ecode.code().unwrap() {
0 => (),
num => {
eprintln!("{}", ecode.to_string());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment