]> git.proxmox.com Git - proxmox.git/commitdiff
product-config: add open_secret_lockfile
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 12 Jun 2024 13:28:54 +0000 (15:28 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 13 Jun 2024 09:14:36 +0000 (11:14 +0200)
We need this for things like shadow.json.lock.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
proxmox-product-config/src/filesystem_helpers.rs

index 4a7fabd4e96f4a419e982ce497dbfe1ea9ff6f95..1a12304a5601ac20d176d947e4635eecc07fcf1e 100644 (file)
@@ -142,3 +142,22 @@ pub fn open_api_lockfile<P: AsRef<Path>>(
     let file = proxmox_sys::fs::open_file_locked(&path, timeout, exclusive, options)?;
     Ok(ApiLockGuard(Some(file)))
 }
+///
+/// Open or create a lock file owned by root and lock it.
+///
+/// File mode is `0600`.
+/// Default timeout is 10 seconds.
+///
+/// The lock is released as soon as you drop the returned lock guard.
+///
+/// Note: This method needs to be called by user `root`.
+pub fn open_secret_lockfile<P: AsRef<Path>>(
+    path: P,
+    timeout: Option<std::time::Duration>,
+    exclusive: bool,
+) -> Result<ApiLockGuard, Error> {
+    let options = secret_create_options();
+    let timeout = timeout.unwrap_or(std::time::Duration::new(10, 0));
+    let file = proxmox_sys::fs::open_file_locked(&path, timeout, exclusive, options)?;
+    Ok(ApiLockGuard(Some(file)))
+}