summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-12-27 02:35:47 +0100
committerLennart Poettering <lennart@poettering.net>2014-12-28 02:08:40 +0100
commit086821244b5113f00a0ef993b78dc56aae2a8f6c (patch)
tree296492582d2fc44697d98505907e3a0ab678451c /src/shared
parent1b9cebf6385b5ea0e5ea099da163687013ac7790 (diff)
machined: add "machinectl remove" for removing images
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_;