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 ADE281FF2C6 for ; Tue, 9 Jul 2024 12:47:26 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2E6211D821; Tue, 9 Jul 2024 12:47:28 +0200 (CEST) From: Stoiko Ivanov To: pve-devel@lists.proxmox.com Date: Tue, 9 Jul 2024 12:47:03 +0200 Message-Id: <20240709104705.1681395-4-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240709104705.1681395-1-s.ivanov@proxmox.com> References: <20240709104705.1681395-1-s.ivanov@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.075 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [docs.rs, pool.rs] Subject: [pve-devel] [PATCH proxmox-offline-mirror v2 3/5] pool: unlink_file: fix check for empty directory X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" path.is_empty() checks for the empty-path, not an empty directory [0]. as the check that the path is below the link_dir happens anyways in the if we can directly call std::fs::remove_dir (which is even safer than the std::fs::remove_dir_all call used in pool::remove_dir()). the oversight seems to have been in place since the intial commit. I ran across the issue when removing many snapshots of a Debian Bookworm repository, syncing this to a medium, and still having a vast amount of empty directories left behind (as debian has one directory per package), which in turn increases the sync run-time. [0] https://docs.rs/nix/latest/nix/trait.NixPath.html#tymethod.is_empty Signed-off-by: Stoiko Ivanov --- src/pool.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pool.rs b/src/pool.rs index 611dcc9..b4f2a6a 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -428,11 +428,11 @@ impl PoolLockGuard<'_> { while let Some(parent) = path.parent() { path = parent; - if !self.pool.path_in_link_dir(path) || !path.is_empty() { + if !self.pool.path_in_link_dir(path) || path.read_dir()?.next().is_some() { break; } - remove_dir(path)?; + std::fs::remove_dir(path)?; } Ok(()) -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel