mirror of
https://github.com/systemd/systemd.git
synced 2025-01-27 18:04:05 +03:00
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.
This commit is contained in:
parent
5ef46e5f65
commit
1bf36bf9ef
@ -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;
|
||||
|
||||
r = image_make(NULL, dirfd(d), path, de->d_name, &image);
|
||||
if (hashmap_contains(h, pretty))
|
||||
continue;
|
||||
|
||||
r = image_make(pretty, dirfd(d), path, de->d_name, &image);
|
||||
if (IN_SET(r, 0, -ENOENT))
|
||||
continue;
|
||||
if (r < 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user