From 7ee2aa1b94f246f7508c0ca47d4caa9e784daa55 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 25 Dec 2018 11:59:02 +0100 Subject: [PATCH] touch_chunk: use libc::lutimensat --- src/backup/chunk_store.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/backup/chunk_store.rs b/src/backup/chunk_store.rs index f75744aa..47a4c65c 100644 --- a/src/backup/chunk_store.rs +++ b/src/backup/chunk_store.rs @@ -154,7 +154,24 @@ impl ChunkStore { let digest_str = digest_to_hex(&digest); chunk_path.push(&digest_str); - std::fs::metadata(&chunk_path)?; + const UTIME_NOW: i64 = ((1 << 30) - 1); + const UTIME_OMIT: i64 = ((1 << 30) - 2); + + let mut times: [libc::timespec; 2] = [ + libc::timespec { tv_sec: 0, tv_nsec: UTIME_NOW }, + libc::timespec { tv_sec: 0, tv_nsec: UTIME_OMIT } + ]; + + use nix::NixPath; + + let res = chunk_path.with_nix_path(|cstr| unsafe { + libc::utimensat(-1, cstr.as_ptr(), ×[0], libc::AT_SYMLINK_NOFOLLOW) + })?; + + if let Err(err) = nix::errno::Errno::result(res) { + bail!("updata atime failed for chunk {:?} - {}", chunk_path, err); + } + Ok(()) }