all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 1/2] pbs-config: add 'create_mocked_lock' helper
Date: Mon,  6 Sep 2021 15:07:34 +0200	[thread overview]
Message-ID: <20210906130735.18032-1-d.csapak@proxmox.com> (raw)

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>
---
 pbs-config/src/lib.rs | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/pbs-config/src/lib.rs b/pbs-config/src/lib.rs
index 29811164..c9ed543f 100644
--- a/pbs-config/src/lib.rs
+++ b/pbs-config/src/lib.rs
@@ -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 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"
-- 
2.30.2





             reply	other threads:[~2021-09-06 13:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-06 13:07 Dominik Csapak [this message]
2021-09-06 13:07 ` [pbs-devel] [PATCH proxmox-backup 2/2] tape/inventory: fix the tape tests as user, by mocking the lock Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210906130735.18032-1-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal