summaryrefslogtreecommitdiff
path: root/src/shared/machine-image.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-04-05 17:56:22 +0200
committerLennart Poettering <lennart@poettering.net>2018-05-24 17:01:57 +0200
commit1bf36bf9efafea1ee637e77dd9646c981a325aac (patch)
tree48c9a0262122815116246a3c222cbd765d9f15be /src/shared/machine-image.c
parent5ef46e5f6598d74acbfe963d4feb8dca4e9486b4 (diff)
downloadsystemd-1bf36bf9efafea1ee637e77dd9646c981a325aac.tar.gz
machine-image: fix duplicate detection when discovering images
We need to chop off the .raw suffix from the files we find before we can test it against the hashmap. Hence do that. And while we are at it, we can pass the pretty name into image_make(), since we already have it properly formatted.
Diffstat (limited to 'src/shared/machine-image.c')
-rw-r--r--src/shared/machine-image.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c
index 40fbccd596..d73719e1dd 100644
--- a/src/shared/machine-image.c
+++ b/src/shared/machine-image.c
@@ -410,14 +410,29 @@ int image_discover(ImageClass class, Hashmap *h) {
FOREACH_DIRENT_ALL(de, d, return -errno) {
_cleanup_(image_unrefp) Image *image = NULL;
+ _cleanup_free_ char *truncated = NULL;
+ const char *pretty, *e;
- if (!image_name_is_valid(de->d_name))
+ if (dot_or_dot_dot(de->d_name))
continue;
- if (hashmap_contains(h, de->d_name))
+ e = endswith(de->d_name, ".raw");
+ if (e) {
+ truncated = strndup(de->d_name, e - de->d_name);
+ if (!truncated)
+ return -ENOMEM;
+
+ pretty = truncated;
+ } else
+ pretty = de->d_name;
+
+ if (!image_name_is_valid(pretty))
+ continue;
+
+ if (hashmap_contains(h, pretty))
continue;
- r = image_make(NULL, dirfd(d), path, de->d_name, &image);
+ r = image_make(pretty, dirfd(d), path, de->d_name, &image);
if (IN_SET(r, 0, -ENOENT))
continue;
if (r < 0)