diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-12-30 14:16:34 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-12-30 15:25:29 +0200 |
commit | 776b2c134c3096b8a7cf1742cbcda13f0527e415 (patch) | |
tree | 032ccd40e9db637df1ff68cdb46b8deda1ade27c | |
parent | 6b9553945683e2b01404673e37e8b951b32a993e (diff) | |
download | obnam2-776b2c134c3096b8a7cf1742cbcda13f0527e415.tar.gz |
feat: add GenerationList
Various part of Obnam will need to deal with lists of generations.
Abstract this.
-rw-r--r-- | src/client.rs | 5 | ||||
-rw-r--r-- | src/cmd/list.rs | 5 | ||||
-rw-r--r-- | src/generation.rs | 1 | ||||
-rw-r--r-- | src/lib.rs | 1 |
4 files changed, 7 insertions, 5 deletions
diff --git a/src/client.rs b/src/client.rs index adca373..ec99134 100644 --- a/src/client.rs +++ b/src/client.rs @@ -6,6 +6,7 @@ use crate::chunkid::ChunkId; use crate::chunkmeta::ChunkMeta; use crate::fsentry::{FilesystemEntry, FilesystemKind}; use crate::generation::FinishedGeneration; +use crate::genlist::GenerationList; use chrono::{DateTime, Local}; use log::{debug, error, info, trace}; use reqwest::blocking::Client; @@ -181,7 +182,7 @@ impl BackupClient { Ok(chunk_ids) } - pub fn list_generations(&self) -> anyhow::Result<Vec<FinishedGeneration>> { + pub fn list_generations(&self) -> anyhow::Result<GenerationList> { let url = format!("{}?generation=true", &self.chunks_url()); trace!("list_generations: url={:?}", url); let req = self.client.get(&url).build()?; @@ -195,7 +196,7 @@ impl BackupClient { .iter() .map(|(id, meta)| FinishedGeneration::new(id, meta.ended().map_or("", |s| s))) .collect(); - Ok(finished) + Ok(GenerationList::new(finished)) } pub fn fetch_chunk(&self, chunk_id: &ChunkId) -> anyhow::Result<DataChunk> { diff --git a/src/cmd/list.rs b/src/cmd/list.rs index 70aa0a7..8766e34 100644 --- a/src/cmd/list.rs +++ b/src/cmd/list.rs @@ -3,9 +3,8 @@ use crate::client::{BackupClient, ClientConfig}; pub fn list(config: &ClientConfig) -> anyhow::Result<()> { let client = BackupClient::new(&config.server_url)?; - let mut generations = client.list_generations()?; - generations.sort_by_cached_key(|gen| gen.ended().to_string()); - for finished in generations { + let generations = client.list_generations()?; + for finished in generations.iter() { println!("{} {}", finished.id(), finished.ended()); } diff --git a/src/generation.rs b/src/generation.rs index dc9bf0c..5d04a9f 100644 --- a/src/generation.rs +++ b/src/generation.rs @@ -158,6 +158,7 @@ mod test { /// A finished generation. /// /// A generation is finished when it's on the server. It can be restored. +#[derive(Debug, Clone)] pub struct FinishedGeneration { id: ChunkId, ended: String, @@ -9,6 +9,7 @@ pub mod cmd; pub mod fsentry; pub mod fsiter; pub mod generation; +pub mod genlist; pub mod index; pub mod indexedstore; pub mod server; |