summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/machine-image.c15
-rw-r--r--src/shared/machine-image.h2
2 files changed, 17 insertions, 0 deletions
diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c
index 51f89d5921..fa06a0dc59 100644
--- a/src/shared/machine-image.c
+++ b/src/shared/machine-image.c
@@ -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",
diff --git a/src/shared/machine-image.h b/src/shared/machine-image.h
index 646598f9c8..e17e32f4a5 100644
--- a/src/shared/machine-image.h
+++ b/src/shared/machine-image.h
@@ -51,5 +51,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, image_hashmap_free);
int image_find(const char *name, Image **ret);
int image_discover(Hashmap *map);
+int image_remove(Image *i);
+
const char* image_type_to_string(ImageType t) _const_;
ImageType image_type_from_string(const char *s) _pure_;