summaryrefslogtreecommitdiff
path: root/src/cmd/show_gen.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-03 09:40:43 +0200
committerLars Wirzenius <liw@liw.fi>2021-03-03 10:21:04 +0200
commite3117849f4d9d70ba2edf80cbe5e43761c27d75c (patch)
tree75f690b6fa6ea4c603b47ba8323a9b17a845ae9e /src/cmd/show_gen.rs
parent2862075677ee26c6790b63d8b20e8937a6c4548a (diff)
downloadobnam2-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/show_gen.rs')
-rw-r--r--src/cmd/show_gen.rs13
1 files changed, 2 insertions, 11 deletions
diff --git a/src/cmd/show_gen.rs b/src/cmd/show_gen.rs
index c7a4bdd..143aed6 100644
--- a/src/cmd/show_gen.rs
+++ b/src/cmd/show_gen.rs
@@ -6,19 +6,13 @@ use indicatif::HumanBytes;
use tempfile::NamedTempFile;
pub fn show_generation(config: &ClientConfig, gen_ref: &str) -> 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)?;
let genlist = client.list_generations()?;
let gen_id: String = genlist.resolve(gen_ref)?;
- let gen = client.fetch_generation(&gen_id, &dbname)?;
+ let gen = client.fetch_generation(&gen_id, temp.path())?;
let files = gen.files()?;
let total_bytes = files.iter().fold(0, |acc, file| {
@@ -35,8 +29,5 @@ pub fn show_generation(config: &ClientConfig, gen_ref: &str) -> Result<(), Obnam
println!("file-bytes: {}", HumanBytes(total_bytes));
println!("file-bytes-raw: {}", total_bytes);
- // Delete the temporary file.
- std::fs::remove_file(&dbname)?;
-
Ok(())
}