Skip to content
Snippets Groups Projects
Commit 496ef0b2 authored by nfontrod's avatar nfontrod
Browse files

src/mount.rs: add mount module to display old archive version

parent 3ebc805e
Branches
No related tags found
No related merge requests found
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>, versions: bool) -> () {
let (borg_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 vopt = match versions {
true => String::from("-o versions"),
false => String::from(""),
};
let cmd = format!(
"borg mount {} {} {} {} {}",
globp,
vopt,
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 => (),
num => {
eprintln!("{}", String::from_utf8(output.stderr).unwrap());
exit(num);
}
}
}
/// Unount an borg archive mounted in .mount folder
pub fn umount_archive() -> () {
let (borg_folder, _) = commit::check_path();
let mount_folder = get_mount_folder(&borg_folder);
let cmd = format!("borg umount {}", mount_folder.to_str().unwrap());
let output = Command::new("sh").arg("-c").arg(cmd).output().unwrap();
match output.status.code().unwrap() {
0 => (),
num => {
eprintln!("{}", String::from_utf8(output.stderr).unwrap());
exit(num);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment