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/client.rs | |
parent | 0d6ff366b09fbe37764863cc672741ba34dea56d (diff) | |
download | obnam2-da4ac27a82029d562a9e9c48ce2a709692930cc1.tar.gz |
refactor: use async for "obnam list-files"
Sponsored-by: author
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/client.rs b/src/client.rs index 4ee3d3c..ca0104f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -100,6 +100,35 @@ impl AsyncBackupClient { pub async fn fetch_chunk(&self, chunk_id: &ChunkId) -> Result<DataChunk, ClientError> { self.chunk_client.fetch_chunk(chunk_id).await } + + async fn fetch_generation_chunk(&self, gen_id: &str) -> Result<GenerationChunk, ClientError> { + let chunk_id = ChunkId::recreate(gen_id); + let chunk = self.fetch_chunk(&chunk_id).await?; + let gen = GenerationChunk::from_data_chunk(&chunk)?; + Ok(gen) + } + + pub async fn fetch_generation( + &self, + gen_id: &str, + dbname: &Path, + ) -> Result<LocalGeneration, ClientError> { + let gen = self.fetch_generation_chunk(gen_id).await?; + + // Fetch the SQLite file, storing it in the named file. + let mut dbfile = File::create(&dbname) + .map_err(|err| ClientError::FileCreate(dbname.to_path_buf(), err))?; + for id in gen.chunk_ids() { + let chunk = self.fetch_chunk(id).await?; + dbfile + .write_all(chunk.data()) + .map_err(|err| ClientError::FileWrite(dbname.to_path_buf(), err))?; + } + info!("downloaded generation to {}", dbname.display()); + + let gen = LocalGeneration::open(dbname)?; + Ok(gen) + } } pub struct AsyncChunkClient { |