mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-10-04 07:48:47 +00:00
Bug_fix: don't consider partial match with --file
When running a diagnose/repair using the --file flag, swupd was considering partial matches, for example "--file /ba" would match "/bar", "/baz", "/bat", etc. This commit changes it so it only matches full matches. Foe example: "/bar" will only match "/bar", "/bar/file", but won't match "/barbar". Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit is contained in:
committed by
Castulo J. Martinez
parent
77b499cd0b
commit
be0fa3c69f
+16
-1
@@ -882,15 +882,30 @@ static struct list *keep_matching_path(struct list *all_files)
|
||||
struct list *matching_files = NULL;
|
||||
struct list *iter = NULL;
|
||||
struct file *file;
|
||||
char *tmp_dir = NULL;
|
||||
|
||||
/* when considering the item as a directory, make sure the item
|
||||
* finishes with a forward slash so we can match items accuratelly,
|
||||
* oherwise we can end up with items that partially match */
|
||||
tmp_dir = str_or_die("%s%s", cmdline_option_file, cmdline_option_file[str_len(cmdline_option_file)] == '/' ? "" : "/");
|
||||
|
||||
for (iter = all_files; iter; iter = iter->next) {
|
||||
file = iter->data;
|
||||
if (strncmp(cmdline_option_file, file->filename, str_len(cmdline_option_file)) == 0) {
|
||||
|
||||
/* if the item entered by the user is a file, the match should
|
||||
* be exact, so look for an exact match first, if there is none,
|
||||
* look for a match treating the item as directory */
|
||||
if (str_cmp(cmdline_option_file, file->filename) == 0) {
|
||||
/* preserving the order is important */
|
||||
matching_files = list_append_data(matching_files, file);
|
||||
} else if (strncmp(tmp_dir, file->filename, str_len(tmp_dir)) == 0) {
|
||||
/* preserving the order is important */
|
||||
matching_files = list_append_data(matching_files, file);
|
||||
}
|
||||
}
|
||||
|
||||
free_and_clear_pointer(&tmp_dir);
|
||||
|
||||
return list_head(matching_files);
|
||||
}
|
||||
|
||||
|
||||
@@ -207,4 +207,25 @@ test_setup() {
|
||||
assert_is_output "$expected_output"
|
||||
|
||||
}
|
||||
|
||||
@test "DIA028: Diagnose with --file doesn't consider partial matches" {
|
||||
|
||||
# when using "diagnose --file <ITEM>", swupd will match the ITEM with
|
||||
# either the full name of a file or a directory (recursively), but won't
|
||||
# use partial matches
|
||||
|
||||
run sudo sh -c "$SWUPD diagnose $SWUPD_OPTS --file /ba"
|
||||
|
||||
assert_status_is "$SWUPD_OK"
|
||||
expected_output=$(cat <<-EOM
|
||||
Diagnosing version 20
|
||||
Downloading missing manifests...
|
||||
Inspected 0 files
|
||||
Diagnose successful
|
||||
EOM
|
||||
)
|
||||
assert_is_output "$expected_output"
|
||||
|
||||
}
|
||||
|
||||
#WEIGHT=36
|
||||
|
||||
Reference in New Issue
Block a user