From 10eea49d819851885e76fcaa0d9eff9e6e445f0a Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 27 Mar 2019 10:17:03 +0100 Subject: [PATCH] src/backup/fixed_index.rs: store reference to file Keep it open and locked while index is in use. --- src/backup/fixed_index.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/backup/fixed_index.rs b/src/backup/fixed_index.rs index 556fa1df..fc7d0a3f 100644 --- a/src/backup/fixed_index.rs +++ b/src/backup/fixed_index.rs @@ -7,6 +7,7 @@ use super::chunk_store::*; use std::sync::Arc; use std::io::{Read, Write}; +use std::fs::File; use std::path::{Path, PathBuf}; use std::os::unix::io::AsRawFd; use uuid::Uuid; @@ -29,6 +30,7 @@ pub struct FixedIndexHeader { pub struct FixedIndexReader { store: Arc, + _file: File, filename: PathBuf, chunk_size: usize, pub size: usize, @@ -55,7 +57,7 @@ impl FixedIndexReader { let full_path = store.relative_path(path); - let mut file = std::fs::File::open(&full_path)?; + let mut file = 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); @@ -110,6 +112,7 @@ impl FixedIndexReader { Ok(Self { store, filename: full_path, + _file: file, chunk_size, size, index: data,