]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
portable: allow Detach to match images with different version suffixes
authorLuca Boccassi <luca.boccassi@microsoft.com>
Fri, 5 Feb 2021 21:24:54 +0000 (21:24 +0000)
committerLuca Boccassi <luca.boccassi@microsoft.com>
Wed, 10 Feb 2021 19:07:27 +0000 (19:07 +0000)
src/portable/portable.c

index d18e03afd4fd1adf20cd94e196bc0ba788269c78..77e8d2128740e5b81242467ab4524e1e4a78e1d6 100644 (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);
         }
 }