Select Git revision
mount.rs 11.79 KiB
// SPDX-FileCopyrightText: 2023 Nicolas Fontrodona
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use crate::commit;
use std::fs;
use std::path::PathBuf;
use std::process::{exit, Command};
/// Get the path of the .mount folder
///
/// # Description
/// Get the path of the .mount folder at the root of the project folder. if it
/// doesn't exits, then creates it
fn get_mount_folder(borgfolder: &PathBuf) -> PathBuf {
let mut mount_folder = borgfolder.parent().unwrap().to_path_buf();
mount_folder.push(".mount");
if !mount_folder.is_dir() {
fs::create_dir(&mount_folder).expect("Unable to create .mount directory");
}
mount_folder
}
pub fn mount_archive(
commit: &Option<String>,
path: &Option<String>,
mut versions: bool,
diff: bool,
last: Option<u8>,
) -> () {
if diff & versions {
eprintln!("Diff cannot be performed with version view. Setting versions to false");
versions = false;
}
let (borg_folder, result_folder) = commit::check_path();
let mount_folder = get_mount_folder(&borg_folder);
let globp = match commit {
Some(g) => format!("-a '{}'", g),
None => String::from(""),
};
let mp = match path {
Some(p) => String::from(p),
None => String::from(""),
};
let lastp = match last {
Some(p) => {
if p > 0 {
format!("--last {}", p)
} else {
String::from("")
}
}
None => String::from(""),
};
let vopt = match versions {
true => String::from("-o versions"),
false => String::from(""),
};
let cmd = format!(
"borg mount {} {} {} {} {} {}",
globp,
vopt,
lastp,
borg_folder.to_str().unwrap(),
mount_folder.to_str().unwrap(),
mp
);
let output = Command::new("sh").arg("-c").arg(cmd).output().unwrap();
match output.status.code().unwrap() {
0 => (),