vpick: Make suffix a single string again instead of a strv

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.
This commit is contained in:
Daan De Meyer
2026-02-18 23:14:11 +01:00
committed by Mike Yuan
parent 17a3b387ae
commit 81cef494a6
5 changed files with 17 additions and 19 deletions
+2 -2
View 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;
+12 -14
View 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",
},
};
+1 -1
View 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 {
+1 -1
View 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)) {
+1 -1
View 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,