diff --git a/src/main.rs b/src/main.rs index 88251c94998351efaf63d3781b7cc4745e8e386c_c3JjL21haW4ucnM=..be651cc500077b7c013e14358438f22d0e9465bf_c3JjL21haW4ucnM= 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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());