diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-07-22 17:55:46 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-07-23 19:23:12 +0300 |
commit | da4ac27a82029d562a9e9c48ce2a709692930cc1 (patch) | |
tree | 79fa7899e6c54e0ef9c21e838bebdbd6f8eebc89 /src/cmd/list_files.rs | |
parent | 0d6ff366b09fbe37764863cc672741ba34dea56d (diff) | |
download | obnam2-da4ac27a82029d562a9e9c48ce2a709692930cc1.tar.gz |
refactor: use async for "obnam list-files"
Sponsored-by: author
Diffstat (limited to 'src/cmd/list_files.rs')
-rw-r--r-- | src/cmd/list_files.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/cmd/list_files.rs b/src/cmd/list_files.rs index c5191f7..723781b 100644 --- a/src/cmd/list_files.rs +++ b/src/cmd/list_files.rs @@ -1,10 +1,11 @@ use crate::backup_reason::Reason; -use crate::client::BackupClient; +use crate::client::AsyncBackupClient; use crate::config::ClientConfig; use crate::error::ObnamError; use crate::fsentry::{FilesystemEntry, FilesystemKind}; use structopt::StructOpt; use tempfile::NamedTempFile; +use tokio::runtime::Runtime; #[derive(Debug, StructOpt)] pub struct ListFiles { @@ -14,14 +15,19 @@ pub struct ListFiles { impl ListFiles { pub fn run(&self, config: &ClientConfig) -> Result<(), ObnamError> { + let rt = Runtime::new()?; + rt.block_on(self.run_async(config)) + } + + async fn run_async(&self, config: &ClientConfig) -> Result<(), ObnamError> { let temp = NamedTempFile::new()?; - let client = BackupClient::new(config)?; + let client = AsyncBackupClient::new(config)?; - let genlist = client.list_generations()?; + let genlist = client.list_generations().await?; let gen_id: String = genlist.resolve(&self.gen_id)?; - let gen = client.fetch_generation(&gen_id, temp.path())?; + let gen = client.fetch_generation(&gen_id, temp.path()).await?; for file in gen.files()?.iter()? { let file = file?; println!("{}", format_entry(&file.entry(), file.reason())); |