sys: file locking depends on timer feature

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2022-07-22 11:58:18 +02:00
parent e2e7ea6d62
commit d3364e07fb
2 changed files with 11 additions and 2 deletions

View File

@ -2,6 +2,7 @@ use std::fs::File;
use std::io::{self, BufRead, BufReader, Write};
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd};
use std::path::{Path, PathBuf};
#[cfg(feature = "timer")]
use std::time::Duration;
use anyhow::{bail, format_err, Error};
@ -14,8 +15,10 @@ use serde_json::Value;
use proxmox_lang::try_block;
use crate::error::{SysError, SysResult};
use crate::linux::timer;
use crate::error::SysError;
#[cfg(feature = "timer")]
use crate::{error::SysResult, linux::timer};
use crate::fs::CreateOptions;
@ -346,6 +349,7 @@ pub fn image_size(path: &Path) -> Result<u64, Error> {
}
}
#[cfg(feature = "timer")]
/// Create a file lock using fntl. This function allows you to specify
/// a timeout if you want to avoid infinite blocking.
///
@ -399,6 +403,7 @@ pub fn lock_file<F: AsRawFd>(
Ok(())
}
#[cfg(feature = "timer")]
/// Open or create a lock file (append mode). Then try to
/// acquire a lock using `lock_file()`.
pub fn open_file_locked<P: AsRef<Path>>(

View File

@ -12,6 +12,7 @@ use regex::Regex;
use proxmox_borrow::Tied;
#[cfg(feature = "timer")]
use crate::error::SysError;
pub type DirLockGuard = Dir;
@ -264,6 +265,7 @@ where
}
}
#[cfg(feature = "timer")]
/// Attempt to acquire a shared flock on the given path, 'what' and
/// 'would_block_message' are used for error formatting.
pub fn lock_dir_noblock_shared(
@ -274,6 +276,7 @@ pub fn lock_dir_noblock_shared(
do_lock_dir_noblock(path, what, would_block_msg, false)
}
#[cfg(feature = "timer")]
/// Attempt to acquire an exclusive flock on the given path, 'what' and
/// 'would_block_message' are used for error formatting.
pub fn lock_dir_noblock(
@ -284,6 +287,7 @@ pub fn lock_dir_noblock(
do_lock_dir_noblock(path, what, would_block_msg, true)
}
#[cfg(feature = "timer")]
fn do_lock_dir_noblock(
path: &std::path::Path,
what: &str,