diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-01-04 13:30:21 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-01-04 15:02:33 +0200 |
commit | c11b8bb76c50cff6aa481f17907ae7200ac55c01 (patch) | |
tree | f275d30b15891a71f11d8012f0573268310567bf /src/cmd/list_files.rs | |
parent | f73b2a919dc2fe2d92eef6df9b7cab25af083fb3 (diff) | |
download | obnam2-c11b8bb76c50cff6aa481f17907ae7200ac55c01.tar.gz |
feat! record whether file was backed up and why, in a generation
This changes SQL schema.
Diffstat (limited to 'src/cmd/list_files.rs')
-rw-r--r-- | src/cmd/list_files.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/cmd/list_files.rs b/src/cmd/list_files.rs new file mode 100644 index 0000000..aa4bed0 --- /dev/null +++ b/src/cmd/list_files.rs @@ -0,0 +1,42 @@ +use crate::client::BackupClient; +use crate::client::ClientConfig; +use crate::error::ObnamError; +use crate::fsentry::{FilesystemEntry, FilesystemKind}; +use tempfile::NamedTempFile; + +pub fn list_files(config: &ClientConfig, gen_ref: &str) -> anyhow::Result<()> { + // 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 client = BackupClient::new(&config.server_url)?; + + let genlist = client.list_generations()?; + let gen_id: String = match genlist.resolve(gen_ref) { + None => return Err(ObnamError::UnknownGeneration(gen_ref.to_string()).into()), + Some(id) => id, + }; + + let gen = client.fetch_generation(&gen_id, &dbname)?; + for (_, entry, reason) in gen.files()? { + println!("{}", format_entry(&entry, &reason)); + } + + // Delete the temporary file. + std::fs::remove_file(&dbname)?; + + Ok(()) +} + +fn format_entry(e: &FilesystemEntry, reason: &str) -> String { + let kind = match e.kind() { + FilesystemKind::Regular => "-", + FilesystemKind::Directory => "d", + FilesystemKind::Symlink => "l", + }; + format!("{} {} ({})", kind, e.pathbuf().display(), reason) +} |