machine-image: handle nicely if the user asks us to remove a symlinked image

Much like for dirs/raw images lets remove the symlink and not the
destination.
This commit is contained in:
Lennart Poettering 2017-10-04 17:42:23 +02:00
parent 759aaedc5c
commit 9fb0b9c70d
1 changed files with 9 additions and 3 deletions

View File

@ -483,9 +483,15 @@ int image_remove(Image *i) {
switch (i->type) {
case IMAGE_SUBVOLUME:
r = btrfs_subvol_remove(i->path, BTRFS_REMOVE_RECURSIVE|BTRFS_REMOVE_QUOTA);
if (r < 0)
return r;
/* Let's unlink first, maybe it is a symlink? If that works we are happy. Otherwise, let's get out the
* big guns */
if (unlink(i->path) < 0) {
r = btrfs_subvol_remove(i->path, BTRFS_REMOVE_RECURSIVE|BTRFS_REMOVE_QUOTA);
if (r < 0)
return r;
}
break;
case IMAGE_DIRECTORY: