diff options
author | Luca Boccassi <luca.boccassi@microsoft.com> | 2021-02-05 22:24:54 +0100 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@microsoft.com> | 2021-02-10 20:07:27 +0100 |
commit | 9e4079d4111894db0cbd6c51e9f8252c9fd22330 (patch) | |
tree | 16ca99cc98778295237bbe8faf4dd10a613969c2 /src/portable/portable.c | |
parent | test: setup var/tmp in the test image as well (diff) | |
download | systemd-9e4079d4111894db0cbd6c51e9f8252c9fd22330.tar.xz systemd-9e4079d4111894db0cbd6c51e9f8252c9fd22330.zip |
portable: allow Detach to match images with different version suffixes
Diffstat (limited to 'src/portable/portable.c')
-rw-r--r-- | src/portable/portable.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/portable/portable.c b/src/portable/portable.c index d18e03afd4..77e8d21287 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -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); } } |