]> git.proxmox.com Git - proxmox-backup.git/commitdiff
pbs-config: add 'create_mocked_lock' helper
authorDominik Csapak <d.csapak@proxmox.com>
Mon, 6 Sep 2021 15:00:25 +0000 (17:00 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 7 Sep 2021 06:42:02 +0000 (08:42 +0200)
by making the field an option and making it None in the mocked case
this function is only intended for testing and hidden from the docs

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
pbs-config/src/lib.rs

index 29811164207e7efba8e76efb983b8bc9927aa587..bd5430a322125f28441fb80170c5d42f53b9b69b 100644 (file)
@@ -18,7 +18,13 @@ pub fn backup_group() -> Result<nix::unistd::Group, Error> {
     pbs_tools::sys::query_group(BACKUP_GROUP_NAME)?
         .ok_or_else(|| format_err!("Unable to lookup '{}' group.", BACKUP_GROUP_NAME))
 }
-pub struct BackupLockGuard(std::fs::File);
+pub struct BackupLockGuard(Option<std::fs::File>);
+
+#[doc(hidden)]
+/// Note: do not use for production code, this is only intended for tests
+pub unsafe fn create_mocked_lock() -> BackupLockGuard {
+    BackupLockGuard(None)
+}
 
 /// Open or create a lock file owned by user "backup" and lock it.
 ///
@@ -41,7 +47,7 @@ pub fn open_backup_lockfile<P: AsRef<std::path::Path>>(
     let timeout = timeout.unwrap_or(std::time::Duration::new(10, 0));
 
     let file = proxmox::tools::fs::open_file_locked(&path, timeout, exclusive, options)?;
-    Ok(BackupLockGuard(file))
+    Ok(BackupLockGuard(Some(file)))
 }
 
 /// Atomically write data to file owned by "root:backup" with permission "0640"