Skip to content
Snippets Groups Projects
Commit be651cc5 authored by Simon Sapin's avatar Simon Sapin
Browse files

Add --overwrite CLI option

parent 88251c94
No related branches found
No related tags found
1 merge request!1Initial implementation
......@@ -18,6 +18,10 @@
#[structopt(long)]
no_confirm: bool,
/// Overwrite a dataset archive with the same name if it exists
#[structopt(long)]
overwrite: bool,
/// The directory to archive.
/// The dataset name is taken from the last component of this path.
directory: PathBuf,
......@@ -32,7 +36,7 @@
impl NewDataset {
fn run(&self, megafine: &Megafine) -> Result<()> {
println!(
"Creating a dataset from directory {}",
"New dataset from directory {}",
style(self.directory.display()).bold()
);
if !std::fs::metadata(&self.directory)?.is_dir() {
......@@ -65,6 +69,12 @@
let archive_path = megafine.tmp_dir.join(&archive_name);
if archive_path.exists() {
Err(format!("tmp/{} already exists", bold))?
if self.overwrite {
println!("Overwriting tmp/{}", bold)
} else {
Err(format!("tmp/{} already exists", bold))?
}
} else {
println!("Creating tmp/{}", bold);
}
......@@ -69,6 +79,5 @@
}
println!("About to create tmp/{}", bold);
if !self.no_confirm {
let proceed = Confirm::new()
.with_prompt("Continue?")
......@@ -93,7 +102,11 @@
let Tee(mut tmp_file, sha) = zstd.finish()?;
let size = tmp_file.stream_position()?;
tmp_file.as_file_mut().sync_all()?;
tmp_file.persist_noclobber(&archive_path)?;
if self.overwrite {
tmp_file.persist(&archive_path)?;
} else {
tmp_file.persist_noclobber(&archive_path)?;
}
let hash = hex::encode(sha.finalize());
println!("Compressed to {}", style(BinaryBytes(size)).bold());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment