1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-04 21:47:31 +03:00

machine-image: add 'discoverable' flag for images

This new flag indicates whether the image object was found in the search
paths using the usual algorithm, or was instantiated by path.

This is useful for code that wants to know whether an image may be
referenced by its shortened name or must be specified by its full name.
This commit is contained in:
Lennart Poettering 2018-04-17 11:14:57 +02:00
parent 9614bb06ef
commit cf604fd40f
2 changed files with 24 additions and 4 deletions

View File

@ -477,16 +477,32 @@ int image_find(ImageClass class, const char *name, Image **ret) {
if (r < 0)
return r;
if (ret)
(*ret)->discoverable = true;
return 1;
}
if (class == IMAGE_MACHINE && streq(name, ".host"))
return image_make(".host", AT_FDCWD, NULL, "/", NULL, ret);
if (class == IMAGE_MACHINE && streq(name, ".host")) {
r = image_make(".host", AT_FDCWD, NULL, "/", NULL, ret);
if (r < 0)
return r;
if (ret)
(*ret)->discoverable = true;
return r;
}
return -ENOENT;
};
int image_from_path(const char *path, Image **ret) {
/* Note that we don't set the 'discoverable' field of the returned object, because we don't check here whether
* the image is in the image search path. And if it is we don't know if the path we used is actually not
* overriden by another, different image earlier in the search path */
if (path_equal(path, "/"))
return image_make(".host", AT_FDCWD, NULL, "/", NULL, ret);
@ -567,6 +583,8 @@ int image_discover(ImageClass class, Hashmap *h) {
if (r < 0)
return r;
image->discoverable = true;
r = hashmap_put(h, image->name, image);
if (r < 0)
return r;
@ -582,12 +600,13 @@ int image_discover(ImageClass class, Hashmap *h) {
if (r < 0)
return r;
image->discoverable = true;
r = hashmap_put(h, image->name, image);
if (r < 0)
return r;
image = NULL;
}
return 0;

View File

@ -54,7 +54,8 @@ typedef struct Image {
char **machine_info;
char **os_release;
bool metadata_valid;
bool metadata_valid:1;
bool discoverable:1; /* true if we know for sure that image_find() would find the image given just the short name */
void *userdata;
} Image;