]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/backup/fixed_index.rs: store reference to file
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 27 Mar 2019 09:17:03 +0000 (10:17 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 27 Mar 2019 09:17:03 +0000 (10:17 +0100)
Keep it open and locked while index is in use.

src/backup/fixed_index.rs

index 556fa1dfd06dfd0de79b028c10d63953b34c81fa..fc7d0a3ff27a193c6f788648bcb741329e66c5fc 100644 (file)
@@ -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<ChunkStore>,
+    _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,