Skip to content
Snippets Groups Projects
Verified Commit 3736d053 authored by nfontrod's avatar nfontrod
Browse files

src/compact.rs: add compact module

parent 56492b50
Branches
No related tags found
No related merge requests found
use crate::commit;
use clap::Args;
use std::process::{exit, Command, Stdio};
#[derive(Debug, Args)]
pub(crate) struct Compact {
/// Cleanup commit-only 17-byte segment files
#[clap(
long = "cleanup-commits",
takes_value = false,
help_heading = "Optional arguments",
display_order = 2
)]
cleanup_commits: bool,
/// Set minimum threshold for saved space in PERCENT (Default: 10)
#[clap(
long,
value_name = "PERCENT",
help_heading = "Optional arguments",
default_value = "10",
display_order = 3
)]
threshold: usize,
/// Display the progression of compaction
///
/// If a lots of segment need compaction, then `compact command may take a
/// wile using --progress is a good idea
#[clap(
long,
takes_value = false,
help_heading = "Optional arguments",
display_order = 1
)]
progress: bool,
/// Enable verbose mode
#[clap(
short,
long,
takes_value = false,
help_heading = "Optional arguments",
display_order = 1
)]
verbose: bool,
}
/// Function that launches borg compact
/// # Arguments
/// - comp: Compact struct containing arguments passed to gblkt compact
pub(crate) fn launch_compact(comp: Compact) {
let mut margs: Vec<String> = Vec::new();
if comp.progress {
margs.push("--progress".to_owned());
}
if comp.verbose {
margs.push("--verbose".to_owned());
}
if comp.cleanup_commits {
margs.push("--cleanup-commits".to_owned());
}
if comp.threshold != 10 {
margs.push("--threshold".to_owned());
margs.push(comp.threshold.to_string());
}
let (borg_folder, _) = commit::check_path();
margs.push(borg_folder.to_str().unwrap().to_string());
let mut output = Command::new("borg")
.arg("compact")
.args(margs)
.stdout(Stdio::piped())
.spawn()
.unwrap_or_else(|e| {
eprintln!("An error occured during borg compact ! {}", e);
exit(804);
});
let ecode = output.wait().expect("error");
match ecode.code().unwrap() {
0 => (),
num => {
eprintln!("{}", ecode.to_string());
exit(num);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment