Fix #1941: remove empty directories when freeing image on FS based storages
Remove directories if they are empty, which can happen if all images from a VM got deleted, e.g., after destroying said VM. Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
committed by
Thomas Lamprecht
parent
4e8de9ad56
commit
712e27f178
@ -5,6 +5,7 @@ use warnings;
|
|||||||
|
|
||||||
use File::chdir;
|
use File::chdir;
|
||||||
use File::Path;
|
use File::Path;
|
||||||
|
use File::Basename;
|
||||||
|
|
||||||
use PVE::Tools qw(run_command);
|
use PVE::Tools qw(run_command);
|
||||||
use PVE::JSONSchema qw(get_standard_option);
|
use PVE::JSONSchema qw(get_standard_option);
|
||||||
@ -689,6 +690,11 @@ sub free_image {
|
|||||||
|
|
||||||
unlink($path) || die "unlink '$path' failed - $!\n";
|
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;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user