From 391a2e43ff99684155033c5677c46c762d3cb03d Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 8 Dec 2018 11:25:11 +0100 Subject: [PATCH] chunk_store.insert_chunk: return information about existing chunks --- src/backup/chunk_store.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/backup/chunk_store.rs b/src/backup/chunk_store.rs index 47b9e4c9..b88370fa 100644 --- a/src/backup/chunk_store.rs +++ b/src/backup/chunk_store.rs @@ -151,7 +151,7 @@ impl ChunkStore { }) } - pub fn insert_chunk(&mut self, chunk: &[u8]) -> Result<([u8; 32]), Error> { + pub fn insert_chunk(&mut self, chunk: &[u8]) -> Result<(bool, [u8; 32]), Error> { self.hasher.reset(); self.hasher.input(chunk); @@ -170,7 +170,7 @@ impl ChunkStore { if let Ok(metadata) = std::fs::metadata(&chunk_path) { if metadata.is_file() { - return Ok(digest); + return Ok((true, digest)); } else { bail!("Got unexpected file type for chunk {}", digest_str); } @@ -195,7 +195,7 @@ impl ChunkStore { drop(lock); - Ok(digest) + Ok((false, digest)) } } @@ -210,8 +210,11 @@ fn test_chunk_store1() { assert!(chunk_store.is_err()); let mut chunk_store = ChunkStore::create(".testdir").unwrap(); - chunk_store.insert_chunk(&[0u8, 1u8]).unwrap(); - chunk_store.insert_chunk(&[0u8, 1u8]).unwrap(); + let (exists, _) = chunk_store.insert_chunk(&[0u8, 1u8]).unwrap(); + assert!(!exists); + + let (exists, _) = chunk_store.insert_chunk(&[0u8, 1u8]).unwrap(); + assert!(exists); let chunk_store = ChunkStore::create(".testdir");