src/backup/chunk_store.rs: avoid create/unlink race

This commit is contained in:
Dietmar Maurer 2019-03-31 10:03:01 +02:00
parent c374f05499
commit 15a77c4c2e
1 changed files with 3 additions and 2 deletions

View File

@ -266,7 +266,8 @@ impl ChunkStore {
continue; continue;
} }
let filename = entry.file_name(); let lock = self.mutex.lock();
if let Ok(stat) = fstatat(dirfd, filename, nix::fcntl::AtFlags::AT_SYMLINK_NOFOLLOW) { if let Ok(stat) = fstatat(dirfd, filename, nix::fcntl::AtFlags::AT_SYMLINK_NOFOLLOW) {
let age = now - stat.st_atime; let age = now - stat.st_atime;
//println!("FOUND {} {:?}", age/(3600*24), filename); //println!("FOUND {} {:?}", age/(3600*24), filename);
@ -285,9 +286,9 @@ impl ChunkStore {
} else { } else {
status.disk_chunks += 1; status.disk_chunks += 1;
status.disk_bytes += stat.st_size as usize; status.disk_bytes += stat.st_size as usize;
} }
} }
drop(lock);
} }
Ok(()) Ok(())
} }