fix #6969: plugin: keep content directory when freeing its last file

After removing a volume, free_image tries to remove the parent
directory, so that no empty per-guest directories are left behind once
all images of a guest are gone. This was done unconditionally, so
deleting the last ISO, container template, snippet or import file also
removed the shared content directory like 'snippets' or 'template/iso'.

The directory gets re-created shortly after by pvestatd, but as
root:root with default permissions, losing any ownership or mode that
the admin set up, for example to allow a non-root user to upload
snippets.

Only clean up the parent directory for guest images, which are the only
volumes stored in per-guest directories.

Signed-off-by: Michal Fox <me@dualfroz.com>
This commit is contained in:
dualfroz committed 2026-09-25 11:30:43 +02:00
1 parent 40459bfd61
commit 43d4bbbdb2
3 files changed
+55 -3

No files matched your search

+3 -3
View File
@@ -1166,9 +1166,9 @@ sub free_image {
}
# 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);
# all images from a guest got deleted, but keep the shared content type dirs
my ($vtype) = $class->parse_volname($volname);
rmdir(dirname($path)) if $vtype eq 'images';
return undef;
}