]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/portable/portabled-image.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 #include "portabled-image.h"
7 Image
*manager_image_cache_get(Manager
*m
, const char *name_or_path
) {
10 return hashmap_get(m
->image_cache
, name_or_path
);
13 static int image_cache_flush(sd_event_source
*s
, void *userdata
) {
14 Manager
*m
= userdata
;
19 hashmap_clear_with_destructor(m
->image_cache
, image_unref
);
23 static int manager_image_cache_initialize(Manager
*m
) {
28 r
= hashmap_ensure_allocated(&m
->image_cache
, &string_hash_ops
);
32 /* We flush the cache as soon as we are idle again */
33 if (!m
->image_cache_defer_event
) {
34 r
= sd_event_add_defer(m
->event
, &m
->image_cache_defer_event
, image_cache_flush
, m
);
38 r
= sd_event_source_set_priority(m
->image_cache_defer_event
, SD_EVENT_PRIORITY_IDLE
);
43 r
= sd_event_source_set_enabled(m
->image_cache_defer_event
, SD_EVENT_ONESHOT
);
50 int manager_image_cache_add(Manager
*m
, Image
*image
) {
55 /* We add the specified image to the cache under two keys.
57 * 1. Always under its path
59 * 2. If the image was discovered in the search path (i.e. its discoverable boolean set) we'll also add it
60 * under its short name.
63 r
= manager_image_cache_initialize(m
);
69 r
= hashmap_put(m
->image_cache
, image
->path
, image
);
75 if (image
->discoverable
) {
76 r
= hashmap_put(m
->image_cache
, image
->name
, image
);
86 int manager_image_cache_discover(Manager
*m
, Hashmap
*images
, sd_bus_error
*error
) {
93 /* A wrapper around image_discover() (for finding images in search path) and portable_discover_attached() (for
94 * finding attached images). */
96 r
= image_discover(IMAGE_PORTABLE
, images
);
100 HASHMAP_FOREACH(image
, images
, i
)
101 (void) manager_image_cache_add(m
, image
);