From: Dietmar Maurer Date: Thu, 2 Jan 2020 12:26:28 +0000 (+0100) Subject: src/backup/chunk_store.rs: implement cond_touch_chunk() X-Git-Tag: v0.1.3~211 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=2585a8a4e236716c1e9dc362d96411a400d5ef7e;p=proxmox-backup.git src/backup/chunk_store.rs: implement cond_touch_chunk() This will be used by backup sync to test if a chunk already exists. --- diff --git a/src/backup/chunk_store.rs b/src/backup/chunk_store.rs index 0f29b659..76a2b3bc 100644 --- a/src/backup/chunk_store.rs +++ b/src/backup/chunk_store.rs @@ -173,6 +173,11 @@ impl ChunkStore { } pub fn touch_chunk(&self, digest: &[u8; 32]) -> Result<(), Error> { + self.cond_touch_chunk(digest, true)?; + Ok(()) + } + + pub fn cond_touch_chunk(&self, digest: &[u8; 32], fail_if_not_exist: bool) -> Result { let (chunk_path, _digest_str) = self.chunk_path(digest); @@ -187,14 +192,19 @@ impl ChunkStore { use nix::NixPath; let res = chunk_path.with_nix_path(|cstr| unsafe { - libc::utimensat(-1, cstr.as_ptr(), ×[0], libc::AT_SYMLINK_NOFOLLOW) + let tmp = libc::utimensat(-1, cstr.as_ptr(), ×[0], libc::AT_SYMLINK_NOFOLLOW); + nix::errno::Errno::result(tmp) })?; - if let Err(err) = nix::errno::Errno::result(res) { + if let Err(err) = res { + if !fail_if_not_exist && err.as_errno() == Some(nix::errno::Errno::ENOENT) { + return Ok(false); + } + bail!("updata atime failed for chunk {:?} - {}", chunk_path, err); } - Ok(()) + Ok(true) } pub fn read_chunk(&self, digest: &[u8; 32]) -> Result { diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index 7e1861ce..91776ad5 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -299,6 +299,10 @@ impl DataStore { self.chunk_store.chunk_path(digest) } + pub fn cond_touch_chunk(&self, digest: &[u8; 32], fail_if_not_exist: bool) -> Result { + self.chunk_store.cond_touch_chunk(digest, fail_if_not_exist) + } + pub fn insert_chunk( &self, chunk: &DataBlob,