[pve-devel] [PATCH v2 #1941 storage] Plugin: Remove empty directories on VM destroy
Christian Ebner
c.ebner at proxmox.com
Thu Jan 24 14:58:22 CET 2019
Remove directories if they are empty after destroying a VM.
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
Version 2:
* Changed comment to suggested text
* removed File::Basename:: prefix to dirname()
PVE/Storage/Plugin.pm | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index e0c2a4e..7dbb41d 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -5,6 +5,7 @@ use warnings;
use File::chdir;
use File::Path;
+use File::Basename;
use PVE::Tools qw(run_command);
use PVE::JSONSchema qw(get_standard_option);
@@ -689,6 +690,11 @@ sub free_image {
unlink($path) || die "unlink '$path' failed - $!\n";
}
+
+ # try to cleanup directory to not clutter storage with empty $vmid dirs if
+ # all images from a guest got deleted
+ my $dir = dirname($path);
+ rmdir($dir);
return undef;
}
--
2.11.0
More information about the pve-devel
mailing list