/** * as_validator_add_issue: **/ static void as_validator_add_issue (AsValidator *validator, AsIssueImportance importance, AsIssueKind kind, const gchar *format, ...) { va_list args; gchar *buffer; gchar *str; gchar *id_str; g_autofree gchar *fname = NULL; AsValidatorIssue *issue; AsValidatorPrivate *priv = GET_PRIVATE (validator); va_start (args, format); buffer = g_strdup_vprintf (format, args); va_end (args); issue = as_validator_issue_new (); as_validator_issue_set_kind (issue, kind); as_validator_issue_set_importance (issue, importance); as_validator_issue_set_message (issue, buffer); g_free (buffer); /* find location */ if (priv->current_fname == NULL) fname = g_strdup ("<unknown>"); else fname = g_strdup (priv->current_fname); if (priv->current_cpt == NULL) str = g_strdup_printf ("%s:<root>", fname); else if (as_str_empty (as_component_get_id (priv->current_cpt))) str = g_strdup_printf ("%s:???", fname); else str = g_strdup_printf ("%s:%s", fname, as_component_get_id (priv->current_cpt)); as_validator_issue_set_location (issue, str); g_free (str); id_str = g_strdup_printf ("%s - %s", as_validator_issue_get_location (issue), as_validator_issue_get_message (issue)); /* str ownership is transferred to the hashtable */ g_hash_table_insert (priv->issues, id_str, issue); }
/** * as_data_pool_update_extension_info: * * Populate the "extensions" property of an #AsComponent, using the * "extends" information from other components. */ static void as_data_pool_update_extension_info (AsDataPool *dpool, AsComponent *cpt) { guint i; GPtrArray *extends; AsDataPoolPrivate *priv = GET_PRIVATE (dpool); extends = as_component_get_extends (cpt); if ((extends == NULL) || (extends->len == 0)) return; for (i = 0; i < extends->len; i++) { AsComponent *extended_cpt; const gchar *extended_cid = (const gchar*) g_ptr_array_index (extends, i); extended_cpt = g_hash_table_lookup (priv->cpt_table, extended_cid); if (extended_cpt == NULL) { g_debug ("%s extends %s, but %s was not found.", as_component_get_id (cpt), extended_cid, extended_cid); return; } as_component_add_extension (extended_cpt, as_component_get_id (cpt)); } }
/** * as_pool_refine_data: * * Automatically refine the data we have about software components in the pool. * * Returns: %TRUE if all metadata was used, %FALSE if we skipped some stuff. */ static gboolean as_pool_refine_data (AsPool *pool) { GHashTableIter iter; gpointer key, value; GHashTable *refined_cpts; gboolean ret = TRUE; AsPoolPrivate *priv = GET_PRIVATE (pool); /* since we might remove stuff from the pool, we need a new table to store the result */ refined_cpts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_object_unref); g_hash_table_iter_init (&iter, priv->cpt_table); while (g_hash_table_iter_next (&iter, &key, &value)) { AsComponent *cpt; const gchar *cdid; cpt = AS_COMPONENT (value); cdid = (const gchar*) key; /* validate the component */ if (!as_component_is_valid (cpt)) { g_debug ("WARNING: Skipped component '%s': The component is invalid.", as_component_get_id (cpt)); ret = FALSE; continue; } /* set the "addons" information */ as_pool_update_addon_info (pool, cpt); /* add to results table */ g_hash_table_insert (refined_cpts, g_strdup (cdid), g_object_ref (cpt)); } /* set refined components as new pool content */ g_hash_table_unref (priv->cpt_table); priv->cpt_table = refined_cpts; return ret; }
/** * as_pool_get_components_by_id: * @pool: An instance of #AsPool. * @cid: The AppStream-ID to look for. * * Get a specific component by its ID. * This function may contain multiple results if we have * data describing this component from multiple scopes/origin types. * * Returns: (transfer container) (element-type AsComponent): An #AsComponent */ GPtrArray* as_pool_get_components_by_id (AsPool *pool, const gchar *cid) { AsPoolPrivate *priv = GET_PRIVATE (pool); GPtrArray *result; GHashTableIter iter; gpointer value; result = g_ptr_array_new_with_free_func (g_object_unref); if (cid == NULL) return result; g_hash_table_iter_init (&iter, priv->cpt_table); while (g_hash_table_iter_next (&iter, NULL, &value)) { AsComponent *cpt = AS_COMPONENT (value); if (g_strcmp0 (as_component_get_id (cpt), cid) == 0) g_ptr_array_add (result, g_object_ref (cpt)); } return result; }
/** * as_utils_build_data_id_for_cpt: * @cpt: The component to build the ID for. * * Builds the unique metadata ID for component @cpt. */ gchar* as_utils_build_data_id_for_cpt (AsComponent *cpt) { const gchar *origin; AsBundleKind bundle_kind; /* determine bundle - what should we do if there are multiple bundles of different types * defined for one component? */ bundle_kind = as_utils_get_component_bundle_kind (cpt); /* NOTE: packages share one namespace, therefore we edit the origin here for now. */ if (bundle_kind == AS_BUNDLE_KIND_PACKAGE) origin = "os"; else origin = as_component_get_origin (cpt); /* build the data-id */ return as_utils_build_data_id (as_component_get_scope (cpt), origin, bundle_kind, as_component_get_id (cpt)); }
/** * as_validator_add_issue: **/ static void as_validator_add_issue (AsValidator *validator, xmlNode *node, AsIssueImportance importance, AsIssueKind kind, const gchar *format, ...) { va_list args; gchar *buffer; gchar *id_str; g_autofree gchar *location = NULL; AsValidatorIssue *issue; AsValidatorPrivate *priv = GET_PRIVATE (validator); va_start (args, format); buffer = g_strdup_vprintf (format, args); va_end (args); issue = as_validator_issue_new (); as_validator_issue_set_kind (issue, kind); as_validator_issue_set_importance (issue, importance); as_validator_issue_set_message (issue, buffer); g_free (buffer); /* update location information */ if (priv->current_fname != NULL) as_validator_issue_set_filename (issue, priv->current_fname); if (priv->current_cpt != NULL) as_validator_issue_set_cid (issue, as_component_get_id (priv->current_cpt)); if (node != NULL) as_validator_issue_set_line (issue, node->line); location = as_validator_issue_get_location (issue); id_str = g_strdup_printf ("%s - %s", location, as_validator_issue_get_message (issue)); /* str ownership is transferred to the hashtable */ g_hash_table_insert (priv->issues, id_str, issue); }
/** * as_pool_add_component: * @pool: An instance of #AsPool * @cpt: The #AsComponent to add to the pool. * @error: A #GError or %NULL * * Register a new component in the AppStream metadata pool. * * Returns: %TRUE if the new component was successfully added to the pool. */ gboolean as_pool_add_component (AsPool *pool, AsComponent *cpt, GError **error) { const gchar *cdid = NULL; AsComponent *existing_cpt; gint pool_priority; AsPoolPrivate *priv = GET_PRIVATE (pool); cdid = as_component_get_data_id (cpt); existing_cpt = g_hash_table_lookup (priv->cpt_table, cdid); /* add additional data to the component, e.g. external screenshots. Also refines * the component's icon paths */ as_component_complete (cpt, priv->screenshot_service_url, priv->icon_dirs); if (existing_cpt == NULL) { g_hash_table_insert (priv->cpt_table, g_strdup (cdid), g_object_ref (cpt)); return TRUE; } /* perform metadata merges if necessary */ if (as_component_get_merge_kind (cpt) != AS_MERGE_KIND_NONE) { g_autoptr(GPtrArray) matches = NULL; guint i; /* we merge the data into all components with matching IDs at time */ matches = as_pool_get_components_by_id (pool, as_component_get_id (cpt)); for (i = 0; i < matches->len; i++) { AsComponent *match = AS_COMPONENT (g_ptr_array_index (matches, i)); as_merge_components (match, cpt); } return TRUE; } /* if we are here, we might have duplicates and no merges, so check if we should replace a component * with data of higher priority, or if we have an actual error in the metadata */ pool_priority = as_component_get_priority (existing_cpt); if (pool_priority < as_component_get_priority (cpt)) { g_hash_table_replace (priv->cpt_table, g_strdup (cdid), g_object_ref (cpt)); g_debug ("Replaced '%s' with data of higher priority.", cdid); } else { /* bundles are treated specially here */ if ((!as_component_has_bundle (existing_cpt)) && (as_component_has_bundle (cpt))) { GPtrArray *bundles; /* propagate bundle information to existing component */ bundles = as_component_get_bundles (cpt); as_component_set_bundles_array (existing_cpt, bundles); return TRUE; } /* experimental multiarch support */ if (as_component_get_architecture (cpt) != NULL) { if (as_arch_compatible (as_component_get_architecture (cpt), priv->current_arch)) { const gchar *earch; /* this component is compatible with our current architecture */ earch = as_component_get_architecture (existing_cpt); if (earch != NULL) { if (as_arch_compatible (earch, priv->current_arch)) { g_hash_table_replace (priv->cpt_table, g_strdup (cdid), g_object_ref (cpt)); g_debug ("Preferred component for native architecture for %s (was %s)", cdid, earch); return TRUE; } else { g_debug ("Ignored additional entry for '%s' on architecture %s.", cdid, earch); return FALSE; } } } } if (pool_priority == as_component_get_priority (cpt)) { g_set_error (error, AS_POOL_ERROR, AS_POOL_ERROR_COLLISION, "Detected colliding ids: %s was already added with the same priority.", cdid); return FALSE; } else { g_set_error (error, AS_POOL_ERROR, AS_POOL_ERROR_COLLISION, "Detected colliding ids: %s was already added with a higher priority.", cdid); return FALSE; } } return TRUE; }
/** * as_validator_analyze_component_metainfo_relation_cb: * * Helper function for GHashTable foreach iteration. */ static void as_validator_analyze_component_metainfo_relation_cb (const gchar *fname, AsComponent *cpt, struct MInfoCheckData *data) { g_autofree gchar *cid_base = NULL; /* if we have no component-id, we can't check anything */ if (as_component_get_id (cpt) == NULL) return; as_validator_set_current_cpt (data->validator, cpt); as_validator_set_current_fname (data->validator, fname); /* check if the fname and the component-id match */ if (g_str_has_suffix (as_component_get_id (cpt), ".desktop")) { cid_base = g_strndup (as_component_get_id (cpt), g_strrstr (as_component_get_id (cpt), ".") - as_component_get_id (cpt)); } else { cid_base = g_strdup (as_component_get_id (cpt)); } if (!as_matches_metainfo (fname, cid_base)) { /* the name-without-type didn't match - check for the full id in the component name */ if (!as_matches_metainfo (fname, as_component_get_id (cpt))) { as_validator_add_issue (data->validator, NULL, AS_ISSUE_IMPORTANCE_WARNING, AS_ISSUE_KIND_WRONG_NAME, "The metainfo filename does not match the component ID."); } } /* check if the referenced .desktop file exists */ if (as_component_get_kind (cpt) == AS_COMPONENT_KIND_DESKTOP_APP) { if (g_hash_table_contains (data->desktop_fnames, as_component_get_desktop_id (cpt))) { g_autofree gchar *desktop_fname_full = NULL; g_autoptr(GKeyFile) dfile = NULL; GError *tmp_error = NULL; desktop_fname_full = g_build_filename (data->apps_dir, as_component_get_desktop_id (cpt), NULL); dfile = g_key_file_new (); g_key_file_load_from_file (dfile, desktop_fname_full, G_KEY_FILE_NONE, &tmp_error); if (tmp_error != NULL) { as_validator_add_issue (data->validator, NULL, AS_ISSUE_IMPORTANCE_WARNING, AS_ISSUE_KIND_READ_ERROR, "Unable to read associated .desktop file: %s", tmp_error->message); g_error_free (tmp_error); tmp_error = NULL; } else { /* we successfully opened the .desktop file, now perform some checks */ /* name */ if (as_str_empty (as_component_get_name (cpt)) && (!g_key_file_has_key (dfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL))) { /* we don't have a summary, and there is also none in the .desktop file - this is bad. */ as_validator_add_issue (data->validator, NULL, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_MISSING, "The component is missing a name (none found in its metainfo or .desktop file)"); } /* summary */ if (as_str_empty (as_component_get_summary (cpt)) && (!g_key_file_has_key (dfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL))) { /* we don't have a summary, and there is also none in the .desktop file - this is bad. */ as_validator_add_issue (data->validator, NULL, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_MISSING, "The component is missing a summary (none found in its metainfo or .desktop file)"); } /* categories */ if (g_key_file_has_key (dfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_CATEGORIES, NULL)) { g_autofree gchar *cats_str = NULL; g_auto(GStrv) cats = NULL; guint i; cats_str = g_key_file_get_string (dfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_CATEGORIES, NULL); cats = g_strsplit (cats_str, ";", -1); for (i = 0; cats[i] != NULL; i++) { if (as_str_empty (cats[i])) continue; if (!as_utils_is_category_name (cats[i])) { as_validator_add_issue (data->validator, NULL, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "The category '%s' defined in the .desktop file does not exist.", cats[i]); } } } } } else { as_validator_add_issue (data->validator, NULL, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_FILE_MISSING, "Component metadata refers to a non-existing .desktop file."); } } as_validator_clear_current_cpt (data->validator); as_validator_clear_current_fname (data->validator); }
/** * as_validator_analyze_component_metainfo_relation_cb: * * Helper function for GHashTable foreach iteration. */ static void as_validator_analyze_component_metainfo_relation_cb (const gchar *fname, AsComponent *cpt, struct MInfoCheckData *data) { gchar *tmp; /* if we have no component-id, we can't check anything */ if (as_component_get_id (cpt) == NULL) return; as_validator_set_current_cpt (data->validator, cpt); as_validator_set_current_fname (data->validator, fname); /* check if the fname and the component-id match */ tmp = g_strndup (as_component_get_id (cpt), g_strrstr (as_component_get_id (cpt), ".") - as_component_get_id (cpt)); if (!as_matches_metainfo (fname, tmp)) { /* the name-without-type didn't match - check for the full id in the component name */ if (!as_matches_metainfo (fname, as_component_get_id (cpt))) { as_validator_add_issue (data->validator, AS_ISSUE_IMPORTANCE_WARNING, AS_ISSUE_KIND_WRONG_NAME, "The metainfo filename does not match the component ID."); } } g_free (tmp); /* check if the referenced .desktop file exists */ if (as_component_get_kind (cpt) == AS_COMPONENT_KIND_DESKTOP_APP) { if (g_hash_table_contains (data->desktop_fnames, as_component_get_id (cpt))) { g_autofree gchar *desktop_fname_full = NULL; g_autoptr(GKeyFile) dfile = NULL; GError *tmp_error = NULL; desktop_fname_full = g_build_filename (data->apps_dir, as_component_get_id (cpt), NULL); dfile = g_key_file_new (); g_key_file_load_from_file (dfile, desktop_fname_full, G_KEY_FILE_NONE, &tmp_error); if (tmp_error != NULL) { as_validator_add_issue (data->validator, AS_ISSUE_IMPORTANCE_WARNING, AS_ISSUE_KIND_READ_ERROR, "Unable to read associated .desktop file: %s", tmp_error->message); g_error_free (tmp_error); tmp_error = NULL; } else { /* we successfully opened the .desktop file, now perform some checks */ /* name */ if ((g_strcmp0 (as_component_get_name (cpt), "") == 0) && (!g_key_file_has_key (dfile, "Desktop Entry", "Name", NULL))) { /* we don't have a summary, and there is also none in the .desktop file - this is bad. */ as_validator_add_issue (data->validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_MISSING, "The component is missing a name (none found in its metainfo or .desktop file)"); } /* summary */ if ((g_strcmp0 (as_component_get_summary (cpt), "") == 0) && (!g_key_file_has_key (dfile, "Desktop Entry", "Comment", NULL))) { /* we don't have a summary, and there is also none in the .desktop file - this is bad. */ as_validator_add_issue (data->validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_MISSING, "The component is missing a summary (none found in its metainfo or .desktop file)"); } } } else { as_validator_add_issue (data->validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_FILE_MISSING, "Component metadata refers to a non-existing .desktop file."); } } as_validator_clear_current_cpt (data->validator); as_validator_clear_current_fname (data->validator); }
/** * as_validator_validate_component_node: **/ static AsComponent* as_validator_validate_component_node (AsValidator *validator, AsXMLData *xdt, xmlNode *root) { gchar *cpttype; xmlNode *iter; AsComponent *cpt; gchar *metadata_license = NULL; GHashTable *found_tags; const gchar *summary; AsParserMode mode; found_tags = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); mode = as_xmldata_get_parser_mode (xdt); /* validate the resulting AsComponent for sanity */ cpt = as_component_new (); as_xmldata_parse_component_node (xdt, root, cpt, NULL); as_validator_set_current_cpt (validator, cpt); /* check if component type is valid */ cpttype = (gchar*) xmlGetProp (root, (xmlChar*) "type"); if (cpttype != NULL) { if (as_component_kind_from_string (cpttype) == AS_COMPONENT_KIND_UNKNOWN) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "Invalid component type found: %s", cpttype); } } g_free (cpttype); for (iter = root->children; iter != NULL; iter = iter->next) { const gchar *node_name; g_autofree gchar *node_content = NULL; gboolean tag_valid = TRUE; /* discard spaces */ if (iter->type != XML_ELEMENT_NODE) continue; node_name = (const gchar*) iter->name; node_content = (gchar*) xmlNodeGetContent (iter); if (g_strcmp0 (node_name, "id") == 0) { gchar *prop; prop = (gchar*) xmlGetProp (iter, (xmlChar*) "type"); if (prop != NULL) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_INFO, AS_ISSUE_KIND_PROPERTY_INVALID, "The id tag for \"%s\" still contains a 'type' property, probably from an old conversion.", node_content); } g_free (prop); if (as_component_get_kind (cpt) == AS_COMPONENT_KIND_DESKTOP_APP) { if (!g_str_has_suffix (node_content, ".desktop")) as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_WARNING, AS_ISSUE_KIND_VALUE_WRONG, "Component id belongs to a desktop-application, but does not resemble the .desktop file name: \"%s\"", node_content); } } else if (g_strcmp0 (node_name, "metadata_license") == 0) { metadata_license = g_strdup (node_content); as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "pkgname") == 0) { if (g_hash_table_contains (found_tags, node_name)) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_PEDANTIC, AS_ISSUE_KIND_TAG_DUPLICATED, "The tag 'pkgname' appears multiple times. You should evaluate creating a metapackage containing the data in order to avoid defining multiple package names per component."); } } else if (g_strcmp0 (node_name, "source_pkgname") == 0) { if (g_hash_table_contains (found_tags, node_name)) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_TAG_DUPLICATED, "The tag 'source_pkgname' appears multiple times."); } } else if (g_strcmp0 (node_name, "name") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "summary") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "description") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); as_validator_check_description_tag (validator, iter, cpt, mode); } else if (g_strcmp0 (node_name, "icon") == 0) { gchar *prop; prop = as_validator_check_type_property (validator, cpt, iter); if ((g_strcmp0 (prop, "cached") == 0) || (g_strcmp0 (prop, "stock") == 0)) { if (g_strrstr (node_content, "/") != NULL) as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "Icons of type 'stock' or 'cached' must not contain a full or relative path to the icon."); } g_free (prop); } else if (g_strcmp0 (node_name, "url") == 0) { gchar *prop; prop = as_validator_check_type_property (validator, cpt, iter); if (as_url_kind_from_string (prop) == AS_URL_KIND_UNKNOWN) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_PROPERTY_INVALID, "Invalid property for 'url' tag: \"%s\"", prop); } g_free (prop); } else if (g_strcmp0 (node_name, "categories") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); as_validator_check_children_quick (validator, iter, "category", cpt); } else if (g_strcmp0 (node_name, "keywords") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); as_validator_check_children_quick (validator, iter, "keyword", cpt); } else if (g_strcmp0 (node_name, "mimetypes") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); as_validator_check_children_quick (validator, iter, "mimetype", cpt); } else if (g_strcmp0 (node_name, "provides") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "screenshots") == 0) { as_validator_check_children_quick (validator, iter, "screenshot", cpt); } else if (g_strcmp0 (node_name, "project_license") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "project_group") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "developer_name") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "compulsory_for_desktop") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "releases") == 0) { as_validator_check_children_quick (validator, iter, "release", cpt); } else if ((g_strcmp0 (node_name, "languages") == 0) && (mode == AS_PARSER_MODE_DISTRO)) { as_validator_check_appear_once (validator, iter, found_tags, cpt); as_validator_check_children_quick (validator, iter, "lang", cpt); } else if ((g_strcmp0 (node_name, "translation") == 0) && (mode == AS_PARSER_MODE_UPSTREAM)) { g_autofree gchar *prop = NULL; AsTranslationKind trkind; prop = as_validator_check_type_property (validator, cpt, iter); trkind = as_translation_kind_from_string (prop); if (trkind == AS_TRANSLATION_KIND_UNKNOWN) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "Unknown type '%s' for <translation/> tag.", prop); } } else if (g_strcmp0 (node_name, "extends") == 0) { } else if (g_strcmp0 (node_name, "bundle") == 0) { g_autofree gchar *prop = NULL; prop = as_validator_check_type_property (validator, cpt, iter); if ((g_strcmp0 (prop, "limba") != 0) && (g_strcmp0 (prop, "xdg-app") != 0)) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "Unknown type '%s' for <bundle/> tag.", prop); } } else if (g_strcmp0 (node_name, "update_contact") == 0) { if (mode == AS_PARSER_MODE_DISTRO) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_WARNING, AS_ISSUE_KIND_TAG_NOT_ALLOWED, "The 'update_contact' tag should not be included in distro AppStream XML."); } else { as_validator_check_appear_once (validator, iter, found_tags, cpt); } } else if (g_strcmp0 (node_name, "metadata") == 0) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_PEDANTIC, AS_ISSUE_KIND_TAG_UNKNOWN, "Found custom metadata in <metadata/> tag. Use of this tag is common, but should be avoided if possible."); tag_valid = FALSE; } else if (!g_str_has_prefix (node_name, "x-")) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_WARNING, AS_ISSUE_KIND_TAG_UNKNOWN, "Found invalid tag: '%s'. Non-standard tags must be prefixed with \"x-\".", node_name); tag_valid = FALSE; } if (tag_valid) { as_validator_check_content_empty (validator, node_content, node_name, AS_ISSUE_IMPORTANCE_WARNING, cpt); } } g_hash_table_unref (found_tags); if (metadata_license == NULL) { if (mode == AS_PARSER_MODE_UPSTREAM) as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_TAG_MISSING, "The essential tag 'metadata_license' is missing."); } else { g_free (metadata_license); } /* check if the summary is sane */ summary = as_component_get_summary (cpt); if ((summary != NULL) && ((strstr (summary, "\n") != NULL) || (strstr (summary, "\t") != NULL))) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "The summary tag must not contain tabs or linebreaks."); } /* check if we have a description */ if (as_str_empty (as_component_get_description (cpt))) { AsComponentKind cpt_kind; cpt_kind = as_component_get_kind (cpt); if ((cpt_kind == AS_COMPONENT_KIND_DESKTOP_APP) || (cpt_kind == AS_COMPONENT_KIND_FONT)) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_TAG_MISSING, "The component is missing a long description. Components of this type must have a long description."); } else if (cpt_kind != AS_COMPONENT_KIND_GENERIC) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_INFO, AS_ISSUE_KIND_TAG_MISSING, "The component is missing a long description. It is recommended to add one."); } } /* validate font specific stuff */ if (as_component_get_kind (cpt) == AS_COMPONENT_KIND_FONT) { if (!g_str_has_suffix (as_component_get_id (cpt), ".font")) as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "Components of type 'font' must have an AppStream ID with a '.font' suffix."); if (as_component_get_provided_for_kind (cpt, AS_PROVIDED_KIND_FONT) == NULL) as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_WARNING, AS_ISSUE_KIND_TAG_MISSING, "Type 'font' component, but no font information was provided via a provides/font tag."); } /* validate addon specific stuff */ if (as_component_get_extends (cpt)->len > 0) { if (as_component_get_kind (cpt) != AS_COMPONENT_KIND_ADDON) as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_TAG_NOT_ALLOWED, "An 'extends' tag is specified, but the component is not an addon."); } else { if (as_component_get_kind (cpt) == AS_COMPONENT_KIND_ADDON) as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_TAG_MISSING, "The component is an addon, but no 'extends' tag was specified."); } as_validator_clear_current_cpt (validator); return cpt; }
/** * as_validator_validate_component_node: **/ static AsComponent* as_validator_validate_component_node (AsValidator *validator, AsXMLData *xdt, xmlNode *root) { xmlNode *iter; AsComponent *cpt; guint i; g_autofree gchar *metadata_license = NULL; g_autofree gchar *cpttype = NULL; g_autoptr(GHashTable) found_tags = NULL; g_auto(GStrv) cid_parts = NULL; const gchar *summary; const gchar *cid; AsParserMode mode; found_tags = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); mode = as_xmldata_get_parser_mode (xdt); /* validate the resulting AsComponent for sanity */ cpt = as_component_new (); as_xmldata_parse_component_node (xdt, root, cpt, NULL); as_validator_set_current_cpt (validator, cpt); /* check if component type is valid */ cpttype = (gchar*) xmlGetProp (root, (xmlChar*) "type"); if (cpttype != NULL) { if (as_component_kind_from_string (cpttype) == AS_COMPONENT_KIND_UNKNOWN) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "Invalid component type found: %s", cpttype); } } /* validate the AppStream ID */ cid = as_component_get_id (cpt); cid_parts = g_strsplit (cid, ".", 3); if (g_strv_length (cid_parts) != 3) { if (as_component_get_kind (cpt) == AS_COMPONENT_KIND_DESKTOP_APP) { /* since the ID and .desktop-file-id are tied together, we can't make this an error for desktop apps */ as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_WARNING, AS_ISSUE_KIND_VALUE_WRONG, "The component ID is not a reverse domain-name. Please update the ID and that of the accompanying .desktop file to follow the latest version of the specifications and avoid future issues."); } else { /* anything which isn't a .desktop app should follow the schema though */ as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "The component ID is no reverse domain-name."); } } else { /* some people just add random dots to their ID - check if we have an actual known TLD as first part, to be more certain that this is a reverse domain name * (this issue happens quite often with old .desktop files) */ if (!as_utils_is_tld (cid_parts[0])) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_INFO, AS_ISSUE_KIND_VALUE_WRONG, "The component ID might not follow the reverse domain-name schema (we do not know about the TLD '%s').", cid_parts[0]); } } /* validate characters in AppStream ID */ for (i = 0; cid[i] != '\0'; i++) { /* check if we have a printable, alphanumeric ASCII character or a dot, hyphen or underscore */ if ((!g_ascii_isalnum (cid[i])) && (cid[i] != '.') && (cid[i] != '-') && (cid[i] != '_')) { g_autofree gchar *c = NULL; c = g_utf8_substring (cid, i, i + 1); as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "The component ID contains an invalid character: '%s'", c); } } for (iter = root->children; iter != NULL; iter = iter->next) { const gchar *node_name; g_autofree gchar *node_content = NULL; gboolean tag_valid = TRUE; /* discard spaces */ if (iter->type != XML_ELEMENT_NODE) continue; node_name = (const gchar*) iter->name; node_content = (gchar*) xmlNodeGetContent (iter); if (g_strcmp0 (node_name, "id") == 0) { gchar *prop; prop = (gchar*) xmlGetProp (iter, (xmlChar*) "type"); if (prop != NULL) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_INFO, AS_ISSUE_KIND_PROPERTY_INVALID, "The id tag for \"%s\" still contains a 'type' property, probably from an old conversion.", node_content); } g_free (prop); if (as_component_get_kind (cpt) == AS_COMPONENT_KIND_DESKTOP_APP) { if (!g_str_has_suffix (node_content, ".desktop")) as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_WARNING, AS_ISSUE_KIND_VALUE_WRONG, "Component id belongs to a desktop-application, but does not resemble the .desktop file name: \"%s\"", node_content); } } else if (g_strcmp0 (node_name, "metadata_license") == 0) { metadata_license = g_strdup (node_content); as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "pkgname") == 0) { if (g_hash_table_contains (found_tags, node_name)) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_PEDANTIC, AS_ISSUE_KIND_TAG_DUPLICATED, "The tag 'pkgname' appears multiple times. You should evaluate creating a metapackage containing the data in order to avoid defining multiple package names per component."); } } else if (g_strcmp0 (node_name, "source_pkgname") == 0) { if (g_hash_table_contains (found_tags, node_name)) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_TAG_DUPLICATED, "The tag 'source_pkgname' appears multiple times."); } } else if (g_strcmp0 (node_name, "name") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "summary") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "description") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); as_validator_check_description_tag (validator, iter, cpt, mode); } else if (g_strcmp0 (node_name, "icon") == 0) { gchar *prop; prop = as_validator_check_type_property (validator, cpt, iter); if ((g_strcmp0 (prop, "cached") == 0) || (g_strcmp0 (prop, "stock") == 0)) { if (g_strrstr (node_content, "/") != NULL) as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "Icons of type 'stock' or 'cached' must not contain a full or relative path to the icon."); } g_free (prop); } else if (g_strcmp0 (node_name, "url") == 0) { gchar *prop; prop = as_validator_check_type_property (validator, cpt, iter); if (as_url_kind_from_string (prop) == AS_URL_KIND_UNKNOWN) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_PROPERTY_INVALID, "Invalid property for 'url' tag: \"%s\"", prop); } g_free (prop); } else if (g_strcmp0 (node_name, "categories") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); as_validator_check_children_quick (validator, iter, "category", cpt); } else if (g_strcmp0 (node_name, "keywords") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); as_validator_check_children_quick (validator, iter, "keyword", cpt); } else if (g_strcmp0 (node_name, "mimetypes") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); as_validator_check_children_quick (validator, iter, "mimetype", cpt); } else if (g_strcmp0 (node_name, "provides") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "screenshots") == 0) { as_validator_check_children_quick (validator, iter, "screenshot", cpt); } else if (g_strcmp0 (node_name, "project_license") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "project_group") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "developer_name") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "compulsory_for_desktop") == 0) { as_validator_check_appear_once (validator, iter, found_tags, cpt); } else if (g_strcmp0 (node_name, "releases") == 0) { as_validator_check_children_quick (validator, iter, "release", cpt); } else if ((g_strcmp0 (node_name, "languages") == 0) && (mode == AS_PARSER_MODE_DISTRO)) { as_validator_check_appear_once (validator, iter, found_tags, cpt); as_validator_check_children_quick (validator, iter, "lang", cpt); } else if ((g_strcmp0 (node_name, "translation") == 0) && (mode == AS_PARSER_MODE_UPSTREAM)) { g_autofree gchar *prop = NULL; AsTranslationKind trkind; prop = as_validator_check_type_property (validator, cpt, iter); trkind = as_translation_kind_from_string (prop); if (trkind == AS_TRANSLATION_KIND_UNKNOWN) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "Unknown type '%s' for <translation/> tag.", prop); } } else if (g_strcmp0 (node_name, "extends") == 0) { } else if (g_strcmp0 (node_name, "bundle") == 0) { g_autofree gchar *prop = NULL; prop = as_validator_check_type_property (validator, cpt, iter); if ((g_strcmp0 (prop, "limba") != 0) && (g_strcmp0 (prop, "flatpak") != 0)) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "Unknown type '%s' for <bundle/> tag.", prop); } } else if (g_strcmp0 (node_name, "update_contact") == 0) { if (mode == AS_PARSER_MODE_DISTRO) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_WARNING, AS_ISSUE_KIND_TAG_NOT_ALLOWED, "The 'update_contact' tag should not be included in distro AppStream XML."); } else { as_validator_check_appear_once (validator, iter, found_tags, cpt); } } else if (g_strcmp0 (node_name, "metadata") == 0) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_PEDANTIC, AS_ISSUE_KIND_TAG_UNKNOWN, "Found custom metadata in <metadata/> tag. Use of this tag is common, but should be avoided if possible."); tag_valid = FALSE; } else if (!g_str_has_prefix (node_name, "x-")) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_WARNING, AS_ISSUE_KIND_TAG_UNKNOWN, "Found invalid tag: '%s'. Non-standard tags must be prefixed with \"x-\".", node_name); tag_valid = FALSE; } if (tag_valid) { as_validator_check_content_empty (validator, node_content, node_name, AS_ISSUE_IMPORTANCE_WARNING, cpt); } } if (metadata_license == NULL) { if (mode == AS_PARSER_MODE_UPSTREAM) as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_TAG_MISSING, "The essential tag 'metadata_license' is missing."); } /* check if the summary is sane */ summary = as_component_get_summary (cpt); if ((summary != NULL) && ((strstr (summary, "\n") != NULL) || (strstr (summary, "\t") != NULL))) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "The summary tag must not contain tabs or linebreaks."); } /* check if we have a description */ if (as_str_empty (as_component_get_description (cpt))) { AsComponentKind cpt_kind; cpt_kind = as_component_get_kind (cpt); if ((cpt_kind == AS_COMPONENT_KIND_DESKTOP_APP) || (cpt_kind == AS_COMPONENT_KIND_FONT)) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_TAG_MISSING, "The component is missing a long description. Components of this type must have a long description."); } else if (cpt_kind != AS_COMPONENT_KIND_GENERIC) { as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_INFO, AS_ISSUE_KIND_TAG_MISSING, "The component is missing a long description. It is recommended to add one."); } } /* validate font specific stuff */ if (as_component_get_kind (cpt) == AS_COMPONENT_KIND_FONT) { if (!g_str_has_suffix (as_component_get_id (cpt), ".font")) as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_VALUE_WRONG, "Components of type 'font' must have an AppStream ID with a '.font' suffix."); if (as_component_get_provided_for_kind (cpt, AS_PROVIDED_KIND_FONT) == NULL) as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_WARNING, AS_ISSUE_KIND_TAG_MISSING, "Type 'font' component, but no font information was provided via a provides/font tag."); } /* validate addon specific stuff */ if (as_component_get_extends (cpt)->len > 0) { if (as_component_get_kind (cpt) != AS_COMPONENT_KIND_ADDON) as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_TAG_NOT_ALLOWED, "An 'extends' tag is specified, but the component is not an addon."); } else { if (as_component_get_kind (cpt) == AS_COMPONENT_KIND_ADDON) as_validator_add_issue (validator, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_TAG_MISSING, "The component is an addon, but no 'extends' tag was specified."); } as_validator_clear_current_cpt (validator); return cpt; }
/** * as_data_pool_add_component: * @dpool: An instance of #AsDataPool * @cpt: The #AsComponent to add to the pool. * @error: A #GError or %NULL * * Register a new component in the AppStream metadata pool. * * Returns: %TRUE if the new component was successfully added to the pool. */ gboolean as_data_pool_add_component (AsDataPool *dpool, AsComponent *cpt, GError **error) { const gchar *cpt_id; AsComponent *existing_cpt; int priority; AsDataPoolPrivate *priv = GET_PRIVATE (dpool); g_return_val_if_fail (cpt != NULL, FALSE); cpt_id = as_component_get_id (cpt); existing_cpt = g_hash_table_lookup (priv->cpt_table, cpt_id); /* add additional data to the component, e.g. external screenshots. Also refines * the component's icon paths */ as_component_complete (cpt, priv->screenshot_service_url, priv->icon_paths); if (existing_cpt == NULL) { g_hash_table_insert (priv->cpt_table, g_strdup (cpt_id), g_object_ref (cpt)); return TRUE; } /* if we are here, we have duplicates */ priority = as_component_get_priority (existing_cpt); if (priority < as_component_get_priority (cpt)) { g_hash_table_replace (priv->cpt_table, g_strdup (cpt_id), g_object_ref (cpt)); g_debug ("Replaced '%s' with data of higher priority.", cpt_id); } else { gboolean ecpt_has_name; gboolean ncpt_has_name; if ((!as_component_has_bundle (existing_cpt)) && (as_component_has_bundle (cpt))) { GHashTable *bundles; /* propagate bundle information to existing component */ bundles = as_component_get_bundles_table (cpt); as_component_set_bundles_table (existing_cpt, bundles); return TRUE; } ecpt_has_name = as_component_get_name (existing_cpt) != NULL; ncpt_has_name = as_component_get_name (cpt) != NULL; if ((ecpt_has_name) && (!ncpt_has_name)) { /* existing component is updated with data from the new one */ as_data_pool_merge_components (dpool, cpt, existing_cpt); g_debug ("Merged stub data for component %s (<-, based on name)", cpt_id); return TRUE; } if ((!ecpt_has_name) && (ncpt_has_name)) { /* new component is updated with data from the existing component, * then it replaces the prior metadata */ as_data_pool_merge_components (dpool, existing_cpt, cpt); g_hash_table_replace (priv->cpt_table, g_strdup (cpt_id), g_object_ref (cpt)); g_debug ("Merged stub data for component %s (->, based on name)", cpt_id); return TRUE; } if (as_component_get_architecture (cpt) != NULL) { if (as_arch_compatible (as_component_get_architecture (cpt), priv->current_arch)) { const gchar *earch; /* this component is compatible with our current architecture */ earch = as_component_get_architecture (existing_cpt); if (earch != NULL) { if (as_arch_compatible (earch, priv->current_arch)) { g_hash_table_replace (priv->cpt_table, g_strdup (cpt_id), g_object_ref (cpt)); g_debug ("Preferred component for native architecture for %s (was %s)", cpt_id, earch); return TRUE; } else { g_debug ("Ignored additional entry for '%s' on architecture %s.", cpt_id, earch); return FALSE; } } } } if (priority == as_component_get_priority (cpt)) { g_set_error (error, AS_DATA_POOL_ERROR, AS_DATA_POOL_ERROR_COLLISION, "Detected colliding ids: %s was already added with the same priority.", cpt_id); return FALSE; } else { g_set_error (error, AS_DATA_POOL_ERROR, AS_DATA_POOL_ERROR_COLLISION, "Detected colliding ids: %s was already added with a higher priority.", cpt_id); return FALSE; } } return TRUE; }
/** * as_pool_add_component_internal: * @pool: An instance of #AsPool * @cpt: The #AsComponent to add to the pool. * @pedantic_noadd: If %TRUE, always emit an error if component couldn't be added. * @error: A #GError or %NULL * * Internal. */ static gboolean as_pool_add_component_internal (AsPool *pool, AsComponent *cpt, gboolean pedantic_noadd, GError **error) { const gchar *cdid = NULL; AsComponent *existing_cpt; gint pool_priority; AsPoolPrivate *priv = GET_PRIVATE (pool); cdid = as_component_get_data_id (cpt); if (as_component_is_ignored (cpt)) { if (pedantic_noadd) g_set_error (error, AS_POOL_ERROR, AS_POOL_ERROR_FAILED, "Skipping '%s' from inclusion into the pool: Component is ignored.", cdid); return FALSE; } existing_cpt = g_hash_table_lookup (priv->cpt_table, cdid); if (as_component_get_origin_kind (cpt) == AS_ORIGIN_KIND_DESKTOP_ENTRY) { g_autofree gchar *tmp_cdid = NULL; /* .desktop entries might map to existing metadata data with or without .desktop suffix, we need to check for that. * (the .desktop suffix is optional for desktop-application metainfo files, and the desktop-entry parser will automatically * omit it if the desktop-entry-id is following the reverse DNS scheme) */ if (existing_cpt == NULL) { tmp_cdid = g_strdup_printf ("%s.desktop", cdid); existing_cpt = g_hash_table_lookup (priv->cpt_table, tmp_cdid); } } if (existing_cpt == NULL) { /* add additional data to the component, e.g. external screenshots. Also refines * the component's icon paths */ as_component_complete (cpt, priv->screenshot_service_url, priv->icon_dirs); g_hash_table_insert (priv->cpt_table, g_strdup (cdid), g_object_ref (cpt)); return TRUE; } /* perform metadata merges if necessary */ if (as_component_get_merge_kind (cpt) != AS_MERGE_KIND_NONE) { g_autoptr(GPtrArray) matches = NULL; guint i; /* we merge the data into all components with matching IDs at time */ matches = as_pool_get_components_by_id (pool, as_component_get_id (cpt)); for (i = 0; i < matches->len; i++) { AsComponent *match = AS_COMPONENT (g_ptr_array_index (matches, i)); as_merge_components (match, cpt); } return TRUE; } /* if we are here, we might have duplicates and no merges, so check if we should replace a component * with data of higher priority, or if we have an actual error in the metadata */ pool_priority = as_component_get_priority (existing_cpt); if (pool_priority < as_component_get_priority (cpt)) { g_hash_table_replace (priv->cpt_table, g_strdup (cdid), g_object_ref (cpt)); g_debug ("Replaced '%s' with data of higher priority.", cdid); } else { /* bundles are treated specially here */ if ((!as_component_has_bundle (existing_cpt)) && (as_component_has_bundle (cpt))) { GPtrArray *bundles; /* propagate bundle information to existing component */ bundles = as_component_get_bundles (cpt); as_component_set_bundles_array (existing_cpt, bundles); return TRUE; } /* experimental multiarch support */ if (as_component_get_architecture (cpt) != NULL) { if (as_arch_compatible (as_component_get_architecture (cpt), priv->current_arch)) { const gchar *earch; /* this component is compatible with our current architecture */ earch = as_component_get_architecture (existing_cpt); if (earch != NULL) { if (as_arch_compatible (earch, priv->current_arch)) { g_hash_table_replace (priv->cpt_table, g_strdup (cdid), g_object_ref (cpt)); g_debug ("Preferred component for native architecture for %s (was %s)", cdid, earch); return TRUE; } else { g_debug ("Ignored additional entry for '%s' on architecture %s.", cdid, earch); return FALSE; } } } } if (pool_priority == as_component_get_priority (cpt)) { g_set_error (error, AS_POOL_ERROR, AS_POOL_ERROR_COLLISION, "Detected colliding ids: %s was already added with the same priority.", cdid); return FALSE; } else { if (pedantic_noadd) g_set_error (error, AS_POOL_ERROR, AS_POOL_ERROR_COLLISION, "Detected colliding ids: %s was already added with a higher priority.", cdid); return FALSE; } } return TRUE; }