diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-02-06 18:03:49 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-02-06 18:10:47 +0200 |
commit | 534ad38e3aae8354bd6ede94fe7b1b7259a598ec (patch) | |
tree | 5c2ebcb90c80dcb118d7c15ec7fe9aae17cff7f2 /src/indexedstore.rs | |
parent | 375d05a8492c391b229b65a8752c4151ffd5bb20 (diff) | |
download | obnam2-534ad38e3aae8354bd6ede94fe7b1b7259a598ec.tar.gz |
feat: method for listing ids of chunks from file data
This will be useful soon, to enable us to check how many chunks from
file data there is in the repository, to check that an upcoming chunk
size setting works. Also add an API call for returning the ids.
Note that all of this is meant for testing only. It may be best to
disable it in production builds, eventually.
Diffstat (limited to 'src/indexedstore.rs')
-rw-r--r-- | src/indexedstore.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/indexedstore.rs b/src/indexedstore.rs index 3f347dd..f2d1831 100644 --- a/src/indexedstore.rs +++ b/src/indexedstore.rs @@ -1,8 +1,9 @@ -use crate::chunk::DataChunk; +use crate::chunk::{DataChunk, GenerationChunk, GenerationChunkError}; use crate::chunkid::ChunkId; use crate::chunkmeta::ChunkMeta; use crate::index::{Index, IndexError}; use crate::store::{Store, StoreError}; +use std::collections::HashSet; use std::path::Path; /// A store for chunks and their metadata. @@ -21,6 +22,9 @@ pub enum IndexedError { #[error(transparent)] IndexError(#[from] IndexError), + #[error(transparent)] + GenerationChunkError(#[from] GenerationChunkError), + /// An error from Store. #[error(transparent)] SqlError(#[from] StoreError), @@ -64,6 +68,28 @@ impl IndexedStore { Ok(self.index.find_generations()?) } + pub fn find_file_chunks(&self) -> IndexedResult<Vec<ChunkId>> { + let gen_ids = self.find_generations()?; + + let mut sql_chunks: HashSet<ChunkId> = HashSet::new(); + for id in gen_ids { + let gen_chunk = self.store.load(&id)?; + let gen = GenerationChunk::from_data_chunk(&gen_chunk)?; + for sqlite_chunk_id in gen.chunk_ids() { + sql_chunks.insert(sqlite_chunk_id.clone()); + } + } + + let all_chunk_ids = self.index.all_chunks()?; + let file_chunks = all_chunk_ids + .iter() + .filter(|id| !sql_chunks.contains(id)) + .map(|id| id.clone()) + .collect(); + + Ok(file_chunks) + } + pub fn remove(&mut self, id: &ChunkId) -> IndexedResult<()> { self.index.remove_meta(id)?; self.store.delete(id)?; |