mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 00:47:10 +09:00
discover-image: Move some logic to the implementation file
This will allow removing the string-util.h and path-util.h includes as part of #37344.
This commit is contained in:
@@ -136,11 +136,11 @@ int image_clean_pool_operation(Manager *manager, ImageCleanPoolMode mode, Operat
|
||||
|
||||
HASHMAP_FOREACH(image, images) {
|
||||
/* We can't remove vendor images (i.e. those in /usr) */
|
||||
if (IMAGE_IS_VENDOR(image))
|
||||
if (image_is_vendor(image))
|
||||
continue;
|
||||
if (IMAGE_IS_HOST(image))
|
||||
if (image_is_host(image))
|
||||
continue;
|
||||
if (mode == IMAGE_CLEAN_POOL_REMOVE_HIDDEN && !IMAGE_IS_HIDDEN(image))
|
||||
if (mode == IMAGE_CLEAN_POOL_REMOVE_HIDDEN && !image_is_hidden(image))
|
||||
continue;
|
||||
|
||||
r = image_remove(image);
|
||||
|
||||
@@ -299,7 +299,7 @@ static int image_update_quota(Image *i, int fd) {
|
||||
|
||||
assert(i);
|
||||
|
||||
if (IMAGE_IS_VENDOR(i) || IMAGE_IS_HOST(i))
|
||||
if (image_is_vendor(i) || image_is_host(i))
|
||||
return -EROFS;
|
||||
|
||||
if (i->type != IMAGE_SUBVOLUME)
|
||||
@@ -1094,7 +1094,7 @@ int image_remove(Image *i) {
|
||||
|
||||
assert(i);
|
||||
|
||||
if (IMAGE_IS_VENDOR(i) || IMAGE_IS_HOST(i))
|
||||
if (image_is_vendor(i) || image_is_host(i))
|
||||
return -EROFS;
|
||||
|
||||
settings = image_settings_path(i);
|
||||
@@ -1189,7 +1189,7 @@ int image_rename(Image *i, const char *new_name, RuntimeScope scope) {
|
||||
if (!image_name_is_valid(new_name))
|
||||
return -EINVAL;
|
||||
|
||||
if (IMAGE_IS_VENDOR(i) || IMAGE_IS_HOST(i))
|
||||
if (image_is_vendor(i) || image_is_host(i))
|
||||
return -EROFS;
|
||||
|
||||
settings = image_settings_path(i);
|
||||
@@ -1388,7 +1388,7 @@ int image_read_only(Image *i, bool b) {
|
||||
|
||||
assert(i);
|
||||
|
||||
if (IMAGE_IS_VENDOR(i) || IMAGE_IS_HOST(i))
|
||||
if (image_is_vendor(i) || image_is_host(i))
|
||||
return -EROFS;
|
||||
|
||||
/* Make sure we don't interfere with a running nspawn */
|
||||
@@ -1578,7 +1578,7 @@ int image_set_limit(Image *i, uint64_t referenced_max) {
|
||||
|
||||
assert(i);
|
||||
|
||||
if (IMAGE_IS_VENDOR(i) || IMAGE_IS_HOST(i))
|
||||
if (image_is_vendor(i) || image_is_host(i))
|
||||
return -EROFS;
|
||||
|
||||
if (i->type != IMAGE_SUBVOLUME)
|
||||
@@ -1831,6 +1831,24 @@ bool image_in_search_path(
|
||||
return false;
|
||||
}
|
||||
|
||||
bool image_is_vendor(const struct Image *i) {
|
||||
assert(i);
|
||||
|
||||
return i->path && path_startswith(i->path, "/usr");
|
||||
}
|
||||
|
||||
bool image_is_host(const struct Image *i) {
|
||||
assert(i);
|
||||
|
||||
if (i->name && streq(i->name, ".host"))
|
||||
return true;
|
||||
|
||||
if (i->path && path_equal(i->path, "/"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int image_to_json(const struct Image *img, sd_json_variant **ret) {
|
||||
assert(img);
|
||||
|
||||
|
||||
@@ -95,29 +95,14 @@ static inline char **image_extension_release(Image *image, ImageClass class) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline bool IMAGE_IS_HIDDEN(const struct Image *i) {
|
||||
static inline bool image_is_hidden(const struct Image *i) {
|
||||
assert(i);
|
||||
|
||||
return i->name && i->name[0] == '.';
|
||||
}
|
||||
|
||||
static inline bool IMAGE_IS_VENDOR(const struct Image *i) {
|
||||
assert(i);
|
||||
|
||||
return i->path && path_startswith(i->path, "/usr");
|
||||
}
|
||||
|
||||
static inline bool IMAGE_IS_HOST(const struct Image *i) {
|
||||
assert(i);
|
||||
|
||||
if (i->name && streq(i->name, ".host"))
|
||||
return true;
|
||||
|
||||
if (i->path && path_equal(i->path, "/"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
bool image_is_vendor(const struct Image *i);
|
||||
bool image_is_host(const struct Image *i);
|
||||
|
||||
int image_to_json(const struct Image *i, sd_json_variant **ret);
|
||||
|
||||
|
||||
@@ -1766,7 +1766,7 @@ static int manager_enumerate_image_class(Manager *m, TargetClass class) {
|
||||
_cleanup_(target_freep) Target *t = NULL;
|
||||
bool have = false;
|
||||
|
||||
if (IMAGE_IS_HOST(image))
|
||||
if (image_is_host(image))
|
||||
continue; /* We already enroll the host ourselves */
|
||||
|
||||
r = target_new(m, class, image->name, image->path, &t);
|
||||
|
||||
Reference in New Issue
Block a user