chiark / gitweb /
machined: add "machinectl remove" for removing images
[elogind.git] / src / shared / machine-image.c
index 51f89d5921bcaba3893048092b5a3928fbc0f1b1..fa06a0dc59aa74436b17024a9fcee7d3083172cd 100644 (file)
@@ -316,6 +316,21 @@ void image_hashmap_free(Hashmap *map) {
         hashmap_free(map);
 }
 
+int image_remove(Image *i) {
+        int r;
+
+        assert(i);
+
+        if (path_equal(i->path, "/") ||
+            path_startswith(i->path, "/usr"))
+                return -EROFS;
+
+        if (i->type == IMAGE_SUBVOLUME)
+                return btrfs_subvol_remove(i->path);
+        else
+                return rm_rf_dangerous(i->path, false, true, false);
+}
+
 static const char* const image_type_table[_IMAGE_TYPE_MAX] = {
         [IMAGE_DIRECTORY] = "directory",
         [IMAGE_SUBVOLUME] = "subvolume",