From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 814B370AB4 for ; Mon, 6 Sep 2021 17:00:28 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7F88F1311F for ; Mon, 6 Sep 2021 17:00:28 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id C03501310C for ; Mon, 6 Sep 2021 17:00:27 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 899A8445BD for ; Mon, 6 Sep 2021 17:00:27 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Mon, 6 Sep 2021 17:00:25 +0200 Message-Id: <20210906150026.1551456-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.429 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup v2 1/2] pbs-config: add 'create_mocked_lock' helper X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Sep 2021 15:00:28 -0000 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 --- changes from v1: * mark function unsafe, so that it is even more clear that this is not intended for 'normal' code 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..bd5430a3 100644 --- a/pbs-config/src/lib.rs +++ b/pbs-config/src/lib.rs @@ -18,7 +18,13 @@ pub fn backup_group() -> Result { 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); + +#[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>( 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