From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id BD5691FF17E for ; Thu, 11 Dec 2025 16:38:46 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 77F171A55B; Thu, 11 Dec 2025 16:39:28 +0100 (CET) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Thu, 11 Dec 2025 16:38:35 +0100 Message-ID: <20251211153835.180405-9-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251211153835.180405-1-c.ebner@proxmox.com> References: <20251211153835.180405-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1765467531682 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.048 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 8/8] chunk store: move bad chunk filename generation into dedicated 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: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Deduplicate the bad chunk filename generation logic by moving it to be an associated function of `ChunkExt`. Instead of set_extension() garbage collection now uses set_file_name() as well, which boils down to a pop and push [0] as compared to an extension replacement [1]. [0] https://doc.rust-lang.org/src/std/path.rs.html#1455 [1] https://doc.rust-lang.org/src/std/path.rs.html#1524 Signed-off-by: Christian Ebner --- pbs-datastore/src/chunk_store.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pbs-datastore/src/chunk_store.rs b/pbs-datastore/src/chunk_store.rs index f5585d2cb..efd79ec8f 100644 --- a/pbs-datastore/src/chunk_store.rs +++ b/pbs-datastore/src/chunk_store.rs @@ -278,13 +278,11 @@ impl ChunkStore { /// Update access timestamp on all bad chunks for given digest pub(super) fn cond_touch_bad_chunks(&self, digest: &[u8; 32]) -> Result { - let (chunk_path, _digest_str) = self.chunk_path(digest); + let (mut chunk_path, digest_str) = self.chunk_path(digest); let mut is_bad = false; for i in 0..=9 { - let bad_ext = format!("{i}.bad"); - let mut bad_path = chunk_path.clone(); - bad_path.set_extension(bad_ext); - if self.cond_touch_path(&bad_path, false)? { + chunk_path.set_file_name(ChunkExt::bad_chunk_filename(&digest_str, i)); + if self.cond_touch_path(&chunk_path, false)? { is_bad = true; } } @@ -922,7 +920,7 @@ impl ChunkStore { let (mut chunk_path, digest_str) = self.chunk_path(digest); let mut counter = 0; loop { - chunk_path.set_file_name(format!("{digest_str}.{counter}.bad")); + chunk_path.set_file_name(ChunkExt::bad_chunk_filename(&digest_str, counter)); if chunk_path.exists() && counter < 9 { counter += 1; } else { @@ -967,6 +965,10 @@ impl ChunkExt { } None } + + fn bad_chunk_filename(digest_str: &str, counter: usize) -> String { + format!("{digest_str}.{counter}.bad") + } } #[test] -- 2.47.3 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel