[pbs-devel] [PATCH proxmox-backup] api: enhance directory existence check
Markus Frank
m.frank at proxmox.com
Wed Nov 29 15:08:38 CET 2023
Instead of just checking the existence of the path, the code now also checks
whether the directory is empty, continues if it is, and aborts if it is not.
Previously, if a directory were deleted and a directory with the same name
would be created, the old check prevented the creation even though the
directory could be used as a mount point.
Signed-off-by: Markus Frank <m.frank at proxmox.com>
---
src/api2/node/disks/directory.rs | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/api2/node/disks/directory.rs b/src/api2/node/disks/directory.rs
index 5e1cb124..cd7b44a3 100644
--- a/src/api2/node/disks/directory.rs
+++ b/src/api2/node/disks/directory.rs
@@ -155,13 +155,17 @@ pub fn create_datastore_disk(
let mount_point = format!("{}{}", BASE_MOUNT_DIR, &name);
- // check if the default path does exist already and bail if it does
+ // check if the default path does exist already
+ // and bail if it does and is not empty
let default_path = std::path::PathBuf::from(&mount_point);
match std::fs::metadata(&default_path) {
Err(_) => {} // path does not exist
Ok(_) => {
- bail!("path {:?} already exists", default_path);
+ let is_empty = default_path.read_dir()?.next().is_none();
+ if !is_empty {
+ bail!("path {:?} already exists and is not empty", default_path);
+ }
}
}
--
2.39.2
More information about the pbs-devel
mailing list