machine-image: add APIs for converting arbitrary image paths into Image objects

This commit is contained in:
Lennart Poettering 2018-04-06 18:58:28 +02:00
parent 4c2e654b21
commit 2ddf182baa
2 changed files with 16 additions and 0 deletions

View file

@ -469,6 +469,20 @@ int image_find(ImageClass class, const char *name, Image **ret) {
return -ENOENT;
};
int image_from_path(const char *path, Image **ret) {
if (path_equal(path, "/"))
return image_make(".host", AT_FDCWD, NULL, "/", NULL, ret);
return image_make(NULL, AT_FDCWD, NULL, path, NULL, ret);
}
int image_find_harder(ImageClass class, const char *name_or_path, Image **ret) {
if (image_name_is_valid(name_or_path))
return image_find(class, name_or_path, ret);
return image_from_path(name_or_path, ret);
}
int image_discover(ImageClass class, Hashmap *h) {
const char *path;
int r;

View file

@ -66,6 +66,8 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Image*, image_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, image_hashmap_free);
int image_find(ImageClass class, const char *name, Image **ret);
int image_from_path(const char *path, Image **ret);
int image_find_harder(ImageClass class, const char *name_or_path, Image **ret);
int image_discover(ImageClass class, Hashmap *map);
int image_remove(Image *i);