]> git.proxmox.com Git - proxmox.git/commitdiff
sys: file locking depends on timer feature
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 22 Jul 2022 09:58:18 +0000 (11:58 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 22 Jul 2022 09:58:18 +0000 (11:58 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
proxmox-sys/src/fs/file.rs
proxmox-sys/src/fs/read_dir.rs

index ffddc2017240e861ba58f8f32c7db48a3bd79340..75eaaf247e9b5546e831962efbb2be684e76bcf4 100644 (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>>(
index 8c0c5a0d9a39a6f890e1f7d62e855fd34b3b2dea..773baa06e78b53fda1f47b164e31b3b695234585 100644 (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,