[pve-devel] [PATCH proxmox-offline-mirror v2 3/5] pool: unlink_file: fix check for empty directory

Stoiko Ivanov s.ivanov at proxmox.com
Tue Jul 9 12:47:03 CEST 2024


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 <s.ivanov at proxmox.com>
---
 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





More information about the pve-devel mailing list