1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-31 14:50:15 +03:00

portable: allow Detach to match images with different version suffixes

This commit is contained in:
Luca Boccassi 2021-02-05 21:24:54 +00:00
parent 8b535f3aac
commit 9e4079d411

View File

@ -1035,10 +1035,14 @@ static bool marker_matches_image(const char *marker, const char *name_or_path) {
a = last_path_component(marker);
if (image_name_is_valid(name_or_path)) {
const char *e;
const char *e, *underscore;
/* We shall match against an image name. In that case let's compare the last component, and optionally
* allow either a suffix of ".raw" or a series of "/". */
* allow either a suffix of ".raw" or a series of "/".
* But allow matching on a different version of the same image, when a "_" is used as a separator. */
underscore = strchr(name_or_path, '_');
if (underscore)
return strneq(a, name_or_path, underscore - name_or_path);
e = startswith(a, name_or_path);
if (!e)
@ -1048,7 +1052,7 @@ static bool marker_matches_image(const char *marker, const char *name_or_path) {
e[strspn(e, "/")] == 0 ||
streq(e, ".raw");
} else {
const char *b;
const char *b, *underscore;
size_t l;
/* We shall match against a path. Let's ignore any prefix here though, as often there are many ways to
@ -1060,7 +1064,11 @@ static bool marker_matches_image(const char *marker, const char *name_or_path) {
if (strcspn(b, "/") != l)
return false;
return memcmp(a, b, l) == 0;
underscore = strchr(b, '_');
if (underscore)
l = underscore - b;
return strneq(a, b, l);
}
}