machine-image: handle nicely if the user asks us to remove a symlinked image
authorLennart Poettering <lennart@poettering.net>
Wed, 4 Oct 2017 15:42:23 +0000 (17:42 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 26 Oct 2017 15:54:56 +0000 (17:54 +0200)
Much like for dirs/raw images lets remove the symlink and not the
destination.

src/shared/machine-image.c

index a8af1b7..24209fa 100644 (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: