From c597a92c81a679e64f35126405a90f30779d2569 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 27 Mar 2019 10:11:14 +0100 Subject: [PATCH] index file readers: aquire shared lock --- src/backup/dynamic_index.rs | 4 ++++ src/backup/fixed_index.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/backup/dynamic_index.rs b/src/backup/dynamic_index.rs index 91994aa7..2087b58c 100644 --- a/src/backup/dynamic_index.rs +++ b/src/backup/dynamic_index.rs @@ -58,6 +58,10 @@ impl DynamicIndexReader { let mut file = std::fs::File::open(&full_path)?; + if let Err(err) = nix::fcntl::flock(file.as_raw_fd(), nix::fcntl::FlockArg::LockSharedNonblock) { + bail!("unable to get shared lock on {:?} - {}", full_path, err); + } + let header_size = std::mem::size_of::(); // todo: use static assertion when available in rust diff --git a/src/backup/fixed_index.rs b/src/backup/fixed_index.rs index 869ecbe9..556fa1df 100644 --- a/src/backup/fixed_index.rs +++ b/src/backup/fixed_index.rs @@ -57,6 +57,10 @@ impl FixedIndexReader { let mut file = std::fs::File::open(&full_path)?; + if let Err(err) = nix::fcntl::flock(file.as_raw_fd(), nix::fcntl::FlockArg::LockSharedNonblock) { + bail!("unable to get shared lock on {:?} - {}", full_path, err); + } + let header_size = std::mem::size_of::(); // todo: use static assertion when available in rust