diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-03-12 07:52:05 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-03-13 08:55:48 +0200 |
commit | 29e68de7973f2b294c50b7d33ef216a8f095b9f9 (patch) | |
tree | 4103f4c460d0db422b999b4f19097cd489b2a6ca /src/index.rs | |
parent | 5e79c4f9b3e5789d1d40c2144ba6c3b6a868dae7 (diff) | |
download | obnam2-29e68de7973f2b294c50b7d33ef216a8f095b9f9.tar.gz |
feat! rename metadata field "sha256" to "label"
The field still contains a cleartext SHa256 of the cleartext chunk
data, but this makes it clearer that it may contain other data.
This is a breaking change: the server API won't work with an old
client, and the new client won't work with an old server. To avoid the
breakage would require more effort than is warranted at this time,
given the very small number of users of Obnam. Sorry.
Sponsored-by: author
Diffstat (limited to 'src/index.rs')
-rw-r--r-- | src/index.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/index.rs b/src/index.rs index b9d29a2..4a1b9c9 100644 --- a/src/index.rs +++ b/src/index.rs @@ -61,8 +61,8 @@ impl Index { sql::remove(&self.conn, id) } - /// Find chunks with a given checksum. - pub fn find_by_sha256(&self, sha256: &str) -> Result<Vec<ChunkId>, IndexError> { + /// Find chunks with a client-assigned label. + pub fn find_by_label(&self, sha256: &str) -> Result<Vec<ChunkId>, IndexError> { sql::find_by_256(&self.conn, sha256) } @@ -98,7 +98,7 @@ mod test { let mut idx = new_index(dir.path()); idx.insert_meta(id.clone(), meta.clone()).unwrap(); assert_eq!(idx.get_meta(&id).unwrap(), meta); - let ids = idx.find_by_sha256("abc").unwrap(); + let ids = idx.find_by_label("abc").unwrap(); assert_eq!(ids, vec![id]); } @@ -110,7 +110,7 @@ mod test { let dir = tempdir().unwrap(); let mut idx = new_index(dir.path()); idx.insert_meta(id, meta).unwrap(); - assert_eq!(idx.find_by_sha256("def").unwrap().len(), 0) + assert_eq!(idx.find_by_label("def").unwrap().len(), 0) } #[test] @@ -122,7 +122,7 @@ mod test { let mut idx = new_index(dir.path()); idx.insert_meta(id.clone(), meta).unwrap(); idx.remove_meta(&id).unwrap(); - let ids: Vec<ChunkId> = idx.find_by_sha256("abc").unwrap(); + let ids: Vec<ChunkId> = idx.find_by_label("abc").unwrap(); assert_eq!(ids, vec![]); } @@ -193,12 +193,12 @@ mod sql { /// Insert a new chunk's metadata into database. pub fn insert(t: &Transaction, chunkid: &ChunkId, meta: &ChunkMeta) -> Result<(), IndexError> { let chunkid = format!("{}", chunkid); - let sha256 = meta.sha256(); + let label = meta.label(); let generation = if meta.is_generation() { 1 } else { 0 }; let ended = meta.ended(); t.execute( "INSERT INTO chunks (id, sha256, generation, ended) VALUES (?1, ?2, ?3, ?4)", - params![chunkid, sha256, generation, ended], + params![chunkid, label, generation, ended], )?; Ok(()) } |