]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
machine-image: fix duplicate detection when discovering images
authorLennart Poettering <lennart@poettering.net>
Thu, 5 Apr 2018 15:56:22 +0000 (17:56 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 24 May 2018 15:01:57 +0000 (17:01 +0200)
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.

src/shared/machine-image.c

index 40fbccd596b12987a227e0168e9ed57fe8e06a65..d73719e1ddb2f137f7c3825d29c23972cce07dd2 100644 (file)
@@ -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)