use timers with a signal for file locking

* rename lock_file -> open_file_locked,
* add lock_file as a function working on already-opened
  files
* change timeout types to std::time::Duration

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller
2018-12-19 11:08:57 +01:00
parent 8cf6e764ad
commit 1628a4c731
2 changed files with 53 additions and 41 deletions

View File

@ -1,6 +1,7 @@
use failure::*;
use std::path::{Path, PathBuf};
use std::io::Write;
use std::time::Duration;
use crypto::digest::Digest;
use crypto::sha2::Sha512Trunc256;
@ -100,7 +101,8 @@ impl ChunkStore {
lockfile_path.push(".lock");
// make sure only one process/thread/task can use it
let lockfile = tools::lock_file(lockfile_path, 10)?;
let lockfile = tools::open_file_locked(
lockfile_path, Duration::from_secs(10))?;
Ok(ChunkStore {
base,