-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport all-categories-invalid to appstream
- Loading branch information
1 parent
5721c1d
commit 7dcc3c0
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
From 0653448a469e3b61b4b5b54ca13eca7a92b65dd1 Mon Sep 17 00:00:00 2001 | ||
From: Matthias Klumpp <[email protected]> | ||
Date: Thu, 4 Jan 2024 05:12:24 +0100 | ||
Subject: [PATCH] validator: Improve error message if no valid categories were | ||
found | ||
|
||
CC: #577 | ||
--- | ||
src/as-utils-private.h | 2 +- | ||
src/as-utils.c | 4 ++-- | ||
src/as-validator-issue-tag.h | 6 ++++++ | ||
src/as-validator.c | 16 ++++++++++++++-- | ||
4 files changed, 23 insertions(+), 5 deletions(-) | ||
|
||
diff --git a/src/as-utils-private.h b/src/as-utils-private.h | ||
index 319c6638..424a79f1 100644 | ||
--- a/src/as-utils-private.h | ||
+++ b/src/as-utils-private.h | ||
@@ -120,7 +120,7 @@ void as_ref_string_assign_transfer (GRefString **rstr_ptr, GRefString *new_rstr) | ||
AS_INTERNAL_VISIBLE | ||
gboolean as_utils_extract_tarball (const gchar *filename, const gchar *target_dir, GError **error); | ||
|
||
-gboolean as_utils_is_ignored_category_name (const gchar *category_name); | ||
+gboolean as_utils_category_name_is_bad (const gchar *category_name); | ||
|
||
gboolean as_utils_is_platform_triplet_arch (const gchar *arch); | ||
gboolean as_utils_is_platform_triplet_oskernel (const gchar *os); | ||
diff --git a/src/as-utils.c b/src/as-utils.c | ||
index 913a0bae..99ae2e93 100644 | ||
--- a/src/as-utils.c | ||
+++ b/src/as-utils.c | ||
@@ -1358,9 +1358,9 @@ as_utils_category_name_is_bad (const gchar *category_name) | ||
return TRUE; | ||
|
||
/* we want to ignore custom categories */ | ||
- if (g_str_has_prefix (cat, "X-")) | ||
+ if (g_str_has_prefix (category_name, "X-")) | ||
return TRUE; | ||
- if (g_str_has_prefix (cat, "x-")) | ||
+ if (g_str_has_prefix (category_name, "x-")) | ||
return TRUE; | ||
|
||
return FALSE; | ||
diff --git a/src/as-validator-issue-tag.h b/src/as-validator-issue-tag.h | ||
index ff384639..5714dd9c 100644 | ||
--- a/src/as-validator-issue-tag.h | ||
+++ b/src/as-validator-issue-tag.h | ||
@@ -743,6 +743,12 @@ AsValidatorIssueTag as_validator_issue_tag_list[] = { | ||
N_("The category name is not valid. Refer to the XDG Menu Specification for a list of valid category names."), | ||
}, | ||
|
||
+ { "all-categories-ignored", | ||
+ AS_ISSUE_SEVERITY_WARNING, | ||
+ N_("All categories for this component have been ignored, either because they were invalid or because they are of low quality " | ||
+ "(e.g. custom 'X-' prefixed or toolkit ones like 'GTK' or 'Qt'). Please fix your category names, or add more categories."), | ||
+ }, | ||
+ | ||
{ "app-categories-missing", | ||
AS_ISSUE_SEVERITY_ERROR, | ||
N_("This component is in no valid categories, even though it should be. Please check its metainfo file and desktop-entry file."), | ||
diff --git a/src/as-validator.c b/src/as-validator.c | ||
index f09d191e..3424a6e4 100644 | ||
--- a/src/as-validator.c | ||
+++ b/src/as-validator.c | ||
@@ -3398,11 +3398,11 @@ as_validator_validate_component_node (AsValidator *validator, AsContext *ctx, xm | ||
|
||
/* validate categories */ | ||
if (as_component_get_categories (cpt)->len > 0) { | ||
- guint j; | ||
GPtrArray *cat_array; | ||
+ gboolean have_valid_category = FALSE; | ||
|
||
cat_array = as_component_get_categories (cpt); | ||
- for (j = 0; j < cat_array->len; j++) { | ||
+ for (guint j = 0; j < cat_array->len; j++) { | ||
const gchar *category_name = (const gchar *) g_ptr_array_index (cat_array, | ||
j); | ||
|
||
@@ -3411,7 +3411,19 @@ as_validator_validate_component_node (AsValidator *validator, AsContext *ctx, xm | ||
NULL, | ||
"category-invalid", | ||
category_name); | ||
+ continue; | ||
} | ||
+ | ||
+ /* check if the category would be ignored during catalog composition */ | ||
+ if (as_utils_category_name_is_bad (category_name)) | ||
+ continue; | ||
+ | ||
+ have_valid_category = TRUE; | ||
+ } | ||
+ | ||
+ if (!have_valid_category) { | ||
+ /* the user clearly intended there to be categories, yet we ended up with no valid ones */ | ||
+ as_validator_add_issue (validator, NULL, "all-categories-ignored", NULL); | ||
} | ||
} | ||
|