summaryrefslogtreecommitdiff
path: root/src/index.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-02-06 18:03:49 +0200
committerLars Wirzenius <liw@liw.fi>2021-02-06 18:10:47 +0200
commit534ad38e3aae8354bd6ede94fe7b1b7259a598ec (patch)
tree5c2ebcb90c80dcb118d7c15ec7fe9aae17cff7f2 /src/index.rs
parent375d05a8492c391b229b65a8752c4151ffd5bb20 (diff)
downloadobnam2-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/index.rs')
-rw-r--r--src/index.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/index.rs b/src/index.rs
index f7300da..9386e73 100644
--- a/src/index.rs
+++ b/src/index.rs
@@ -75,6 +75,10 @@ impl Index {
pub fn find_generations(&self) -> IndexResult<Vec<ChunkId>> {
sql::find_generations(&self.conn)
}
+
+ pub fn all_chunks(&self) -> IndexResult<Vec<ChunkId>> {
+ sql::find_chunk_ids(&self.conn)
+ }
}
#[cfg(test)]
@@ -243,6 +247,17 @@ mod sql {
Ok(ids)
}
+ pub fn find_chunk_ids(conn: &Connection) -> IndexResult<Vec<ChunkId>> {
+ let mut stmt = conn.prepare("SELECT id FROM chunks WHERE generation IS 0")?;
+ let iter = stmt.query_map(params![], |row| row_to_id(row))?;
+ let mut ids = vec![];
+ for x in iter {
+ let x = x?;
+ ids.push(x);
+ }
+ Ok(ids)
+ }
+
fn row_to_meta(row: &Row) -> rusqlite::Result<ChunkMeta> {
let sha256: String = row.get(row.column_index("sha256")?)?;
let generation: i32 = row.get(row.column_index("generation")?)?;