diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-11-09 10:47:05 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-11-09 10:47:05 +0200 |
commit | 4d5b5c26f7c4b45434448d9ff8eb5d02c5737665 (patch) | |
tree | 84f7678e2fc2bb98239aafeaf75d2efb7ea3d77b /src/client.rs | |
parent | 0809fb0ff525774b90c2a0d33b4b42752bc60b41 (diff) | |
download | obnam2-4d5b5c26f7c4b45434448d9ff8eb5d02c5737665.tar.gz |
fetch gen sqlite file when restoring
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/client.rs b/src/client.rs index 24d961a..ecfc42c 100644 --- a/src/client.rs +++ b/src/client.rs @@ -32,6 +32,12 @@ impl ClientConfig { pub enum ClientError { #[error("Server successful response to creating chunk lacked chunk id")] NoCreatedChunkId, + + #[error("Server does not have chunk {0}")] + ChunkNotFound(String), + + #[error("Server does not have generation {0}")] + GenerationNotFound(String), } pub struct BackupClient { @@ -178,4 +184,34 @@ impl BackupClient { debug!("list_generations: map={:?}", map); Ok(map.keys().into_iter().map(|key| key.into()).collect()) } + + pub fn fetch_chunk(&self, chunk_id: &ChunkId) -> anyhow::Result<DataChunk> { + let url = format!("{}/{}", self.base_url(), chunk_id); + trace!("fetch_chunk: url={:?}", url); + let req = self.client.get(&url).build()?; + let res = self.client.execute(req)?; + debug!("fetch_chunk: status={}", res.status()); + if res.status() != 200 { + return Err(ClientError::ChunkNotFound(chunk_id.to_string()).into()); + } + + let body = res.bytes()?; + Ok(DataChunk::new(body.to_vec())) + } + + pub fn fetch_generation(&self, gen_id: &str) -> anyhow::Result<GenerationChunk> { + let url = format!("{}/{}", self.base_url(), gen_id); + trace!("fetch_generation: url={:?}", url); + let req = self.client.get(&url).build()?; + let res = self.client.execute(req)?; + debug!("fetch_generation: status={}", res.status()); + if res.status() != 200 { + return Err(ClientError::GenerationNotFound(gen_id.to_string()).into()); + } + + let text = res.text()?; + debug!("fetch_generation: text={:?}", text); + let gen = serde_json::from_str(&text)?; + Ok(gen) + } } |