]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
vpick: Make suffix a single string again instead of a strv
authorDaan De Meyer <daan@amutable.com>
Wed, 18 Feb 2026 20:27:45 +0000 (21:27 +0100)
committerMike Yuan <me@yhndnzj.com>
Wed, 18 Feb 2026 22:14:11 +0000 (23:14 +0100)
This was made a strv to handle either directories or raw images but
since we now handle that via multiple PickFilter instances, we don't
need suffixes to be a strv anymore.

src/shared/discover-image.c
src/shared/vpick.c
src/shared/vpick.h
src/test/test-vpick.c
src/vpick/vpick-tool.c

index 5bb547460894b9e39982ce80cf64bb59a14a73ef..8352e5a821b258e1613e3f1c479d0a2c4b697711 100644 (file)
@@ -883,7 +883,7 @@ int image_find(RuntimeScope scope,
                                         .type_mask = endswith(suffix, ".raw") ? (UINT32_C(1) << DT_REG) | (UINT32_C(1) << DT_BLK) : (UINT32_C(1) << DT_DIR),
                                         .basename = name,
                                         .architecture = _ARCHITECTURE_INVALID,
-                                        .suffix = STRV_MAKE(suffix),
+                                        .suffix = suffix,
                                 };
 
                                 _cleanup_(pick_result_done) PickResult result = PICK_RESULT_NULL;
@@ -1100,7 +1100,7 @@ int image_discover(
                                                 .type_mask = endswith(suffix, ".raw") ? (UINT32_C(1) << DT_REG) | (UINT32_C(1) << DT_BLK) : (UINT32_C(1) << DT_DIR),
                                                 .basename = pretty,
                                                 .architecture = _ARCHITECTURE_INVALID,
-                                                .suffix = STRV_MAKE(suffix),
+                                                .suffix = suffix,
                                         };
 
                                         _cleanup_(pick_result_done) PickResult result = PICK_RESULT_NULL;
index f3fd233e17b89683698c198ae024d6713ce25789..69e8be1b166ce546e3a8f739d77e5e19713ba7de 100644 (file)
@@ -13,7 +13,6 @@
 #include "recurse-dir.h"
 #include "stat-util.h"
 #include "string-util.h"
-#include "strv.h"
 #include "vpick.h"
 
 void pick_result_done(PickResult *p) {
@@ -86,8 +85,6 @@ static int format_fname(
 
         if (FLAGS_SET(flags, PICK_TRIES) || !filter->version) /* Underspecified? */
                 return -ENOEXEC;
-        if (strv_length(filter->suffix) > 1) /* suffix is not deterministic? */
-                return -ENOEXEC;
 
         /* The format for names we match goes like this:
          *
@@ -139,8 +136,8 @@ static int format_fname(
                         return -ENOMEM;
         }
 
-        if (!strv_isempty(filter->suffix))
-                if (!strextend(&fn, filter->suffix[0]))
+        if (!isempty(filter->suffix))
+                if (!strextend(&fn, filter->suffix))
                         return -ENOMEM;
 
         if (!filename_is_valid(fn))
@@ -407,8 +404,8 @@ static int make_choice(
                 } else
                         e = dname;
 
-                if (!strv_isempty(filter->suffix)) {
-                        char *sfx = endswith_strv(e, filter->suffix);
+                if (!isempty(filter->suffix)) {
+                        char *sfx = endswith(e, filter->suffix);
                         if (!sfx)
                                 continue;
 
@@ -511,7 +508,6 @@ static int path_pick_one(
                 PickResult *ret) {
 
         _cleanup_free_ char *filter_bname = NULL, *dir = NULL, *parent = NULL, *fname = NULL;
-        char * const *filter_suffix_strv = NULL;
         const char *filter_suffix = NULL, *enumeration_path;
         uint32_t filter_type_mask;
         int r;
@@ -569,11 +565,13 @@ static int path_pick_one(
                         return -ENOMEM;
 
                 /* Chop off suffix, if specified */
-                char *f = endswith_strv(filter_bname, filter->suffix);
-                if (f)
-                        *f = 0;
+                if (!isempty(filter->suffix)) {
+                        char *f = endswith(filter_bname, filter->suffix);
+                        if (f)
+                                *f = 0;
+                }
 
-                filter_suffix_strv = filter->suffix;
+                filter_suffix = filter->suffix;
                 filter_type_mask = filter->type_mask;
 
                 enumeration_path = path;
@@ -633,7 +631,7 @@ static int path_pick_one(
                                 .basename = filter_bname,
                                 .version = filter->version,
                                 .architecture = filter->architecture,
-                                .suffix = filter_suffix_strv ?: STRV_MAKE(filter_suffix),
+                                .suffix = filter_suffix,
                         },
                         flags,
                         ret);
@@ -790,7 +788,7 @@ const PickFilter pick_filter_image_raw[1] = {
         {
                 .type_mask = (UINT32_C(1) << DT_REG) | (UINT32_C(1) << DT_BLK),
                 .architecture = _ARCHITECTURE_INVALID,
-                .suffix = STRV_MAKE(".raw"),
+                .suffix = ".raw",
         },
 };
 
index d08dc58b8fb52a3adb0d57761e9b20b14998420d..1ebcd5c8ab629bb4c76d3db72bce1580b2e215a0 100644 (file)
@@ -17,7 +17,7 @@ typedef struct PickFilter {
         const char *basename;         /* Can be overridden by search pattern */
         const char *version;
         Architecture architecture;
-        char * const *suffix;         /* Can be overridden by search pattern */
+        const char *suffix;           /* Can be overridden by search pattern */
 } PickFilter;
 
 typedef struct PickResult {
index f550b92464496a94e32d5be9579cfb368cfbe4e9..400380b5754f39f45b96c7d420a3e466850f8e6c 100644 (file)
@@ -44,7 +44,7 @@ TEST(path_pick) {
 
         PickFilter filter = {
                 .architecture = _ARCHITECTURE_INVALID,
-                .suffix = STRV_MAKE(".raw"),
+                .suffix = ".raw",
         };
 
         if (IN_SET(native_architecture(), ARCHITECTURE_X86, ARCHITECTURE_X86_64)) {
index f4251f5c943669b1adb84c99af38c5a9ad632788..c20994d115dd5ca9b731de78383040fa81c803cb 100644 (file)
@@ -245,7 +245,7 @@ static int run(int argc, char *argv[]) {
                                       .basename = arg_filter_basename,
                                       .version = arg_filter_version,
                                       .architecture = arg_filter_architecture,
-                                      .suffix = STRV_MAKE(arg_filter_suffix),
+                                      .suffix = arg_filter_suffix,
                                       .type_mask = arg_filter_type_mask,
                               },
                               /* n_filters= */ 1,