summaryrefslogtreecommitdiff
path: root/src/cmd/list_files.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/list_files.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/list_files.rs')
-rw-r--r--src/cmd/list_files.rs13
1 files changed, 2 insertions, 11 deletions
diff --git a/src/cmd/list_files.rs b/src/cmd/list_files.rs
index ec3e52e..71b0d68 100644
--- a/src/cmd/list_files.rs
+++ b/src/cmd/list_files.rs
@@ -6,27 +6,18 @@ use crate::fsentry::{FilesystemEntry, FilesystemKind};
use tempfile::NamedTempFile;
pub fn list_files(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())?;
for file in gen.files()? {
println!("{}", format_entry(&file.entry(), file.reason()));
}
- // Delete the temporary file.
- std::fs::remove_file(&dbname)?;
-
Ok(())
}