diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-03-03 09:40:43 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-03-03 10:21:04 +0200 |
commit | e3117849f4d9d70ba2edf80cbe5e43761c27d75c (patch) | |
tree | 75f690b6fa6ea4c603b47ba8323a9b17a845ae9e /src/cmd/restore.rs | |
parent | 2862075677ee26c6790b63d8b20e8937a6c4548a (diff) | |
download | obnam2-e3117849f4d9d70ba2edf80cbe5e43761c27d75c.tar.gz |
fix: allow generation temporary files to be automatically deleted
By not calling NamedTempFile::persist, the files get deleted
automatically when the file is closed or the struct is dropped.
Previously we were deleting the temporary files manually, which meant
that sometimes they weren't deleted if the program crashed at an
unfortunate time.
Diffstat (limited to 'src/cmd/restore.rs')
-rw-r--r-- | src/cmd/restore.rs | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/src/cmd/restore.rs b/src/cmd/restore.rs index b394d7d..cb42114 100644 --- a/src/cmd/restore.rs +++ b/src/cmd/restore.rs @@ -19,13 +19,7 @@ use structopt::StructOpt; use tempfile::NamedTempFile; pub fn restore(config: &ClientConfig, gen_ref: &str, to: &Path) -> Result<(), ObnamError> { - // Create a named temporary file. We don't meed the open file - // handle, so we discard that. - let dbname = { - let temp = NamedTempFile::new()?; - let (_, dbname) = temp.keep()?; - dbname - }; + let temp = NamedTempFile::new()?; let client = BackupClient::new(config)?; @@ -33,7 +27,7 @@ pub fn restore(config: &ClientConfig, gen_ref: &str, to: &Path) -> Result<(), Ob let gen_id: String = genlist.resolve(gen_ref)?; info!("generation id is {}", gen_id); - let gen = client.fetch_generation(&gen_id, &dbname)?; + let gen = client.fetch_generation(&gen_id, temp.path())?; info!("restoring {} files", gen.file_count()?); let progress = create_progress_bar(gen.file_count()?, true); for file in gen.files()? { @@ -49,9 +43,6 @@ pub fn restore(config: &ClientConfig, gen_ref: &str, to: &Path) -> Result<(), Ob } progress.finish(); - // Delete the temporary file. - std::fs::remove_file(&dbname)?; - Ok(()) } |