summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-07-31 18:03:00 +0100
committerRichard Hughes <richard@hughsie.com>2016-07-31 21:33:04 +0100
commit2df0a81b92c56041f570e3bcb1e976ccaba33a67 (patch)
tree90b08eb6cd4d5fa262425558965a81513e9843b7
parent4322b453952ed597db8bd234f4a0c23b17b394ed (diff)
downloadappstream-glib-2df0a81b92c56041f570e3bcb1e976ccaba33a67.tar.gz
Include the scope in the equality check
-rw-r--r--libappstream-glib/as-app.c84
-rw-r--r--libappstream-glib/as-app.h21
-rw-r--r--libappstream-glib/as-self-test.c4
-rw-r--r--libappstream-glib/as-store.c93
4 files changed, 151 insertions, 51 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index 904a1df..804e3db 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -86,6 +86,7 @@ typedef struct
GPtrArray *translations; /* of AsTranslation */
GPtrArray *vetos; /* of string */
AsAppSourceKind source_kind;
+ AsAppScope scope;
AsAppState state;
AsAppTrustFlags trust_flags;
AsAppQuirk quirk;
@@ -313,6 +314,46 @@ as_app_state_to_string (AsAppState state)
}
/**
+ * as_app_scope_from_string:
+ * @scope: a source kind string
+ *
+ * Converts the text representation to an enumerated value.
+ *
+ * Return value: A #AsAppScope, e.g. %AS_APP_SCOPE_SYSTEM.
+ *
+ * Since: 0.6.1
+ **/
+AsAppScope
+as_app_scope_from_string (const gchar *scope)
+{
+ if (g_strcmp0 (scope, "user") == 0)
+ return AS_APP_SCOPE_USER;
+ if (g_strcmp0 (scope, "system") == 0)
+ return AS_APP_SCOPE_SYSTEM;
+ return AS_APP_SCOPE_UNKNOWN;
+}
+
+/**
+ * as_app_scope_to_string:
+ * @scope: the #AsAppScope, e.g. %AS_APP_SCOPE_SYSTEM
+ *
+ * Converts the enumerated value to an text representation.
+ *
+ * Returns: string version of @scope, or %NULL for unknown
+ *
+ * Since: 0.6.1
+ **/
+const gchar *
+as_app_scope_to_string (AsAppScope scope)
+{
+ if (scope == AS_APP_SCOPE_USER)
+ return "user";
+ if (scope == AS_APP_SCOPE_SYSTEM)
+ return "system";
+ return NULL;
+}
+
+/**
* as_app_guess_source_kind:
* @filename: a file name
*
@@ -483,7 +524,7 @@ as_app_fix_unique_nullable (const gchar *tmp)
*
* Gets the unique ID value to represent the component.
*
- * Returns: the unique ID, e.g. "fedora/desktop/gimp.desktop/i386/master"
+ * Returns: the unique ID, e.g. "system/fedora/desktop/gimp.desktop/i386/master"
*
* Since: 0.6.1
**/
@@ -492,15 +533,19 @@ as_app_get_unique_id (AsApp *app)
{
AsAppPrivate *priv = GET_PRIVATE (app);
if (priv->unique_id == NULL) {
+ const gchar *arch_str = NULL;
const gchar *id_str = NULL;
const gchar *kind_str = NULL;
- const gchar *arch_str = NULL;
+ const gchar *scope_str = NULL;
if (priv->kind != AS_APP_KIND_UNKNOWN)
kind_str = as_app_kind_to_string (priv->kind);
+ if (priv->scope != AS_APP_SCOPE_UNKNOWN)
+ scope_str = as_app_scope_to_string (priv->scope);
id_str = as_app_get_id_no_prefix (app);
if (priv->architectures->len == 1)
arch_str = g_ptr_array_index (priv->architectures, 0);
- priv->unique_id = g_strdup_printf ("%s/%s/%s/%s/%s",
+ priv->unique_id = g_strdup_printf ("%s/%s/%s/%s/%s/%s",
+ as_app_fix_unique_nullable (scope_str),
as_app_fix_unique_nullable (priv->origin),
as_app_fix_unique_nullable (kind_str),
as_app_fix_unique_nullable (id_str),
@@ -1294,6 +1339,23 @@ as_app_get_source_kind (AsApp *app)
}
/**
+ * as_app_get_scope:
+ * @app: a #AsApp instance.
+ *
+ * Gets the scope of the application.
+ *
+ * Returns: enumerated value
+ *
+ * Since: 0.6.1
+ **/
+AsAppScope
+as_app_get_scope (AsApp *app)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ return priv->scope;
+}
+
+/**
* as_app_get_state:
* @app: a #AsApp instance.
*
@@ -1787,6 +1849,22 @@ as_app_set_source_kind (AsApp *app, AsAppSourceKind source_kind)
}
/**
+ * as_app_set_scope:
+ * @app: a #AsApp instance.
+ * @scope: the #AsAppScope.
+ *
+ * Sets the scope of the application.
+ *
+ * Since: 0.6.1
+ **/
+void
+as_app_set_scope (AsApp *app, AsAppScope scope)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ priv->scope = scope;
+}
+
+/**
* as_app_set_state:
* @app: a #AsApp instance.
* @state: the #AsAppState.
diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h
index 8ecfaba..e443cc3 100644
--- a/libappstream-glib/as-app.h
+++ b/libappstream-glib/as-app.h
@@ -275,6 +275,22 @@ typedef enum {
AS_APP_STATE_LAST
} AsAppState;
+/**
+ * AsAppScope:
+ * @AS_APP_SCOPE_UNKNOWN: Unknown scope
+ * @AS_APP_SCOPE_USER: User scope
+ * @AS_APP_SCOPE_SYSTEM: System scope
+ *
+ * The application scope.
+ **/
+typedef enum {
+ AS_APP_SCOPE_UNKNOWN, /* Since: 0.6.1 */
+ AS_APP_SCOPE_USER, /* Since: 0.6.1 */
+ AS_APP_SCOPE_SYSTEM, /* Since: 0.6.1 */
+ /*< private >*/
+ AS_APP_SCOPE_LAST
+} AsAppScope;
+
#define AS_APP_ERROR as_app_error_quark ()
AsApp *as_app_new (void);
@@ -285,10 +301,13 @@ const gchar *as_app_source_kind_to_string (AsAppSourceKind source_kind);
const gchar *as_app_state_to_string (AsAppState state);
const gchar *as_app_kind_to_string (AsAppKind kind);
AsAppKind as_app_kind_from_string (const gchar *kind);
+AsAppScope as_app_scope_from_string (const gchar *scope);
+const gchar *as_app_scope_to_string (AsAppScope scope);
/* getters */
AsAppKind as_app_get_kind (AsApp *app);
AsAppSourceKind as_app_get_source_kind (AsApp *app);
+AsAppScope as_app_get_scope (AsApp *app);
AsAppState as_app_get_state (AsApp *app);
AsAppTrustFlags as_app_get_trust_flags (AsApp *app);
GList *as_app_get_languages (AsApp *app);
@@ -367,6 +386,8 @@ void as_app_set_kind (AsApp *app,
AsAppKind kind);
void as_app_set_source_kind (AsApp *app,
AsAppSourceKind source_kind);
+void as_app_set_scope (AsApp *app,
+ AsAppScope scope);
void as_app_set_state (AsApp *app,
AsAppState state);
void as_app_set_trust_flags (AsApp *app,
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 03289cc..d8e31d6 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -1537,7 +1537,7 @@ as_test_app_func (void)
/* verify */
g_assert_cmpstr (as_app_get_id (app), ==, "org.gnome.Software.desktop");
g_assert_cmpstr (as_app_get_id_filename (app), ==, "org.gnome.Software");
- g_assert_cmpstr (as_app_get_unique_id (app), ==, "*/desktop/org.gnome.Software.desktop/i386/master");
+ g_assert_cmpstr (as_app_get_unique_id (app), ==, "*/*/desktop/org.gnome.Software.desktop/i386/master");
g_assert_cmpstr (as_app_get_name (app, "pl"), ==, "Oprogramowanie");
g_assert_cmpstr (as_app_get_comment (app, NULL), ==, "Application manager");
g_assert_cmpstr (as_app_get_description (app, NULL), ==, "<p>Software allows you to find stuff</p>");
@@ -3025,7 +3025,7 @@ as_test_store_flatpak_func (void)
g_assert_cmpint (apps->len, ==, 1);
app = g_ptr_array_index (apps, 0);
g_assert_cmpstr (as_app_get_id (app), ==, "flatpak:test.desktop");
- g_assert_cmpstr (as_app_get_unique_id (app), ==, "flatpak_remote-name/desktop/test.desktop/x86_64/master");
+ g_assert_cmpstr (as_app_get_unique_id (app), ==, "*/flatpak_remote-name/desktop/test.desktop/x86_64/master");
g_assert_cmpstr (as_app_get_id_filename (app), ==, "test");
g_assert_cmpstr (as_app_get_origin (app), ==, "flatpak_remote-name");
g_assert_cmpstr (as_app_get_source_file (app), ==, filename);
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c
index c15744d..cfbc620 100644
--- a/libappstream-glib/as-store.c
+++ b/libappstream-glib/as-store.c
@@ -79,7 +79,7 @@ typedef struct
} AsStorePrivate;
typedef struct {
- gchar *id_prefix;
+ AsAppScope scope;
gchar *arch;
} AsStorePathData;
@@ -105,7 +105,7 @@ G_DEFINE_QUARK (as-store-error-quark, as_store_error)
static gboolean as_store_from_file_internal (AsStore *store,
GFile *file,
- const gchar *id_prefix,
+ AsAppScope scope,
const gchar *arch,
GCancellable *cancellable,
GError **error);
@@ -971,7 +971,7 @@ as_store_fixup_id_prefix (AsApp *app, const gchar *id_prefix)
static gboolean
as_store_from_root (AsStore *store,
AsNode *root,
- const gchar *id_prefix,
+ AsAppScope scope,
const gchar *icon_prefix,
const gchar *source_filename,
const gchar *arch,
@@ -1064,7 +1064,7 @@ as_store_from_root (AsStore *store,
/* fallback */
if (origin_app == NULL) {
- id_prefix_app = g_strdup (id_prefix);
+ id_prefix_app = g_strdup (as_app_scope_to_string (scope));
origin_app = g_strdup (priv->origin);
}
@@ -1073,10 +1073,6 @@ as_store_from_root (AsStore *store,
g_debug ("using app origin of '%s' rather than '%s'",
origin_app, priv->origin);
}
- if (g_strcmp0 (id_prefix_app, id_prefix) != 0) {
- g_debug ("using app prefix of '%s' rather than '%s'",
- id_prefix_app, id_prefix);
- }
/* guess the icon path after we've read the origin and then look for
* ../icons/$origin if the topdir is 'xmls', falling back to ./icons */
@@ -1299,7 +1295,7 @@ as_store_watch_source_added (AsStore *store, const gchar *filename)
file = g_file_new_for_path (filename);
if (!as_store_from_file_internal (store,
file,
- path_data->id_prefix,
+ path_data->scope,
path_data->arch,
NULL, /* cancellable */
&error)){
@@ -1371,7 +1367,7 @@ as_store_monitor_removed_cb (AsMonitor *monitor,
static void
as_store_add_path_data (AsStore *store,
const gchar *path,
- const gchar *id_prefix,
+ AsAppScope scope,
const gchar *arch)
{
AsStorePrivate *priv = GET_PRIVATE (store);
@@ -1385,28 +1381,33 @@ as_store_add_path_data (AsStore *store,
/* check is a directory */
if (!g_file_test (path, G_FILE_TEST_IS_DIR)) {
g_warning ("not adding path %s [%s:%s] as not a directory",
- path, id_prefix, arch);
+ path, as_app_scope_to_string (scope), arch);
return;
}
/* check not already exists */
path_data = g_hash_table_lookup (priv->appinfo_dirs, path);
if (path_data != NULL) {
- if (g_strcmp0 (path_data->id_prefix, id_prefix) != 0 ||
+ if (path_data->scope != scope ||
g_strcmp0 (path_data->arch, arch) != 0) {
g_warning ("already added path %s [%s:%s] vs new [%s:%s]",
- path, path_data->id_prefix, path_data->arch,
- id_prefix, arch);
+ path,
+ as_app_scope_to_string (path_data->scope),
+ path_data->arch,
+ as_app_scope_to_string (scope),
+ arch);
} else {
g_debug ("already added path %s [%s:%s]",
- path, path_data->id_prefix, path_data->arch);
+ path,
+ as_app_scope_to_string (path_data->scope),
+ path_data->arch);
}
return;
}
/* create new */
path_data = g_slice_new0 (AsStorePathData);
- path_data->id_prefix = g_strdup (id_prefix);
+ path_data->scope = scope;
path_data->arch = g_strdup (arch);
g_hash_table_insert (priv->appinfo_dirs, g_strdup (path), path_data);
}
@@ -1414,7 +1415,7 @@ as_store_add_path_data (AsStore *store,
static gboolean
as_store_from_file_internal (AsStore *store,
GFile *file,
- const gchar *id_prefix,
+ AsAppScope scope,
const gchar *arch,
GCancellable *cancellable,
GError **error)
@@ -1467,7 +1468,7 @@ as_store_from_file_internal (AsStore *store,
/* icon prefix is the directory the XML has been found in */
icon_prefix = g_path_get_dirname (filename);
- return as_store_from_root (store, root, id_prefix,
+ return as_store_from_root (store, root, scope,
icon_prefix, filename, arch, error);
}
@@ -1498,7 +1499,7 @@ as_store_from_file (AsStore *store,
GError **error)
{
return as_store_from_file_internal (store, file,
- NULL, /* id_prefix */
+ AS_APP_SCOPE_UNKNOWN,
NULL, /* arch */
cancellable, error);
}
@@ -1604,7 +1605,7 @@ as_store_from_xml (AsStore *store,
return FALSE;
}
return as_store_from_root (store, root,
- NULL, /* id_prefix */
+ AS_APP_SCOPE_UNKNOWN,
icon_root,
NULL, /* filename */
NULL, /* arch */
@@ -2106,7 +2107,7 @@ as_store_guess_origin_fallback (AsStore *store,
static gboolean
as_store_load_app_info_file (AsStore *store,
- const gchar *id_prefix,
+ AsAppScope scope,
const gchar *path_xml,
const gchar *arch,
GCancellable *cancellable,
@@ -2126,7 +2127,7 @@ as_store_load_app_info_file (AsStore *store,
file = g_file_new_for_path (path_xml);
return as_store_from_file_internal (store,
file,
- id_prefix,
+ scope,
arch,
cancellable,
error);
@@ -2134,7 +2135,7 @@ as_store_load_app_info_file (AsStore *store,
static gboolean
as_store_load_app_info (AsStore *store,
- const gchar *id_prefix,
+ AsAppScope scope,
const gchar *path,
const gchar *arch,
AsStoreLoadFlags flags,
@@ -2179,7 +2180,7 @@ as_store_load_app_info (AsStore *store,
continue;
filename_md = g_build_filename (path, tmp, NULL);
if (!as_store_load_app_info_file (store,
- id_prefix,
+ scope,
filename_md,
arch,
cancellable,
@@ -2196,7 +2197,7 @@ as_store_load_app_info (AsStore *store,
}
/* watch the directories for changes */
- as_store_add_path_data (store, path, id_prefix, arch);
+ as_store_add_path_data (store, path, scope, arch);
if (!as_monitor_add_directory (priv->monitor,
path,
cancellable,
@@ -2244,7 +2245,7 @@ as_store_load_installed_file_is_valid (const gchar *filename)
static gboolean
as_store_load_installed (AsStore *store,
AsStoreLoadFlags flags,
- const gchar *id_prefix,
+ AsAppScope scope,
const gchar *path,
GCancellable *cancellable,
GError **error)
@@ -2265,7 +2266,7 @@ as_store_load_installed (AsStore *store,
return FALSE;
/* watch the directories for changes */
- as_store_add_path_data (store, path, id_prefix, NULL);
+ as_store_add_path_data (store, path, scope, NULL);
if (!as_monitor_add_directory (priv->monitor,
path,
cancellable,
@@ -2314,7 +2315,7 @@ as_store_load_installed (AsStore *store,
}
/* set the correct scope */
- as_store_fixup_id_prefix (app, id_prefix);
+ as_store_fixup_id_prefix (app, as_app_scope_to_string (scope));
/* do not load applications with vetos */
if ((flags & AS_STORE_LOAD_FLAG_ALLOW_VETO) == 0 &&
@@ -2355,13 +2356,14 @@ as_store_load_path (AsStore *store, const gchar *path,
GCancellable *cancellable, GError **error)
{
return as_store_load_installed (store, AS_STORE_LOAD_FLAG_NONE,
- NULL, path, cancellable, error);
+ AS_APP_SCOPE_UNKNOWN,
+ path, cancellable, error);
}
static gboolean
as_store_search_installed (AsStore *store,
AsStoreLoadFlags flags,
- const gchar *id_prefix,
+ AsAppScope scope,
const gchar *path,
GCancellable *cancellable,
GError **error)
@@ -2372,14 +2374,14 @@ as_store_search_installed (AsStore *store,
g_debug ("searching path %s", dest);
if (!g_file_test (dest, G_FILE_TEST_EXISTS))
return TRUE;
- return as_store_load_installed (store, flags, id_prefix,
+ return as_store_load_installed (store, flags, scope,
dest, cancellable, error);
}
static gboolean
as_store_search_app_info (AsStore *store,
AsStoreLoadFlags flags,
- const gchar *id_prefix,
+ AsAppScope scope,
const gchar *path,
GCancellable *cancellable,
GError **error)
@@ -2396,7 +2398,7 @@ as_store_search_app_info (AsStore *store,
NULL);
if (!g_file_test (dest, G_FILE_TEST_EXISTS))
continue;
- if (!as_store_load_app_info (store, id_prefix, dest, NULL,
+ if (!as_store_load_app_info (store, scope, dest, NULL,
flags, cancellable, error))
return FALSE;
}
@@ -2427,28 +2429,28 @@ as_store_search_per_system (AsStore *store,
if ((flags & AS_STORE_LOAD_FLAG_APP_INFO_SYSTEM) > 0) {
g_autofree gchar *dest = NULL;
dest = g_build_filename (data_dirs[i], "app-info", NULL);
- if (!as_store_search_app_info (store, flags, "system",
+ if (!as_store_search_app_info (store, flags, AS_APP_SCOPE_SYSTEM,
dest, cancellable, error))
return FALSE;
}
if ((flags & AS_STORE_LOAD_FLAG_APPDATA) > 0) {
g_autofree gchar *dest = NULL;
dest = g_build_filename (data_dirs[i], "appdata", NULL);
- if (!as_store_search_installed (store, flags, "system",
+ if (!as_store_search_installed (store, flags, AS_APP_SCOPE_SYSTEM,
dest, cancellable, error))
return FALSE;
}
if ((flags & AS_STORE_LOAD_FLAG_APPDATA) > 0) {
g_autofree gchar *dest = NULL;
dest = g_build_filename (data_dirs[i], "metainfo", NULL);
- if (!as_store_search_installed (store, flags, "system",
+ if (!as_store_search_installed (store, flags, AS_APP_SCOPE_SYSTEM,
dest, cancellable, error))
return FALSE;
}
if ((flags & AS_STORE_LOAD_FLAG_DESKTOP) > 0) {
g_autofree gchar *dest = NULL;
dest = g_build_filename (data_dirs[i], "applications", NULL);
- if (!as_store_search_installed (store, flags, "system",
+ if (!as_store_search_installed (store, flags, AS_APP_SCOPE_SYSTEM,
dest, cancellable, error))
return FALSE;
}
@@ -2459,11 +2461,11 @@ as_store_search_per_system (AsStore *store,
g_autofree gchar *dest1 = NULL;
g_autofree gchar *dest2 = NULL;
dest1 = g_build_filename (LOCALSTATEDIR, "lib", "app-info", NULL);
- if (!as_store_search_app_info (store, flags, "system", dest1,
+ if (!as_store_search_app_info (store, flags, AS_APP_SCOPE_SYSTEM, dest1,
cancellable, error))
return FALSE;
dest2 = g_build_filename (LOCALSTATEDIR, "cache", "app-info", NULL);
- if (!as_store_search_app_info (store, flags, "system", dest2,
+ if (!as_store_search_app_info (store, flags, AS_APP_SCOPE_SYSTEM, dest2,
cancellable, error))
return FALSE;
/* ignore the prefix; we actually want to use the
@@ -2472,11 +2474,11 @@ as_store_search_per_system (AsStore *store,
g_autofree gchar *dest3 = NULL;
g_autofree gchar *dest4 = NULL;
dest3 = g_build_filename ("/var", "lib", "app-info", NULL);
- if (!as_store_search_app_info (store, flags, "system",
+ if (!as_store_search_app_info (store, flags, AS_APP_SCOPE_SYSTEM,
dest3, cancellable, error))
return FALSE;
dest4 = g_build_filename ("/var", "cache", "app-info", NULL);
- if (!as_store_search_app_info (store, flags, "system",
+ if (!as_store_search_app_info (store, flags, AS_APP_SCOPE_SYSTEM,
dest4, cancellable, error))
return FALSE;
}
@@ -2500,7 +2502,7 @@ as_store_search_per_user (AsStore *store,
if ((flags & AS_STORE_LOAD_FLAG_APP_INFO_USER) > 0) {
g_autofree gchar *dest = NULL;
dest = g_build_filename (g_get_user_data_dir (), "app-info", NULL);
- if (!as_store_search_app_info (store, flags, "user",
+ if (!as_store_search_app_info (store, flags, AS_APP_SCOPE_USER,
dest, cancellable, error))
return FALSE;
}
@@ -2509,7 +2511,7 @@ as_store_search_per_user (AsStore *store,
if ((flags & AS_STORE_LOAD_FLAG_APPDATA) > 0) {
g_autofree gchar *dest = NULL;
dest = g_build_filename (g_get_user_data_dir (), "appdata", NULL);
- if (!as_store_search_installed (store, flags, "user",
+ if (!as_store_search_installed (store, flags, AS_APP_SCOPE_USER,
dest, cancellable, error))
return FALSE;
}
@@ -2518,7 +2520,7 @@ as_store_search_per_user (AsStore *store,
if ((flags & AS_STORE_LOAD_FLAG_APPDATA) > 0) {
g_autofree gchar *dest = NULL;
dest = g_build_filename (g_get_user_data_dir (), "metainfo", NULL);
- if (!as_store_search_installed (store, flags, "user",
+ if (!as_store_search_installed (store, flags, AS_APP_SCOPE_USER,
dest, cancellable, error))
return FALSE;
}
@@ -2527,7 +2529,7 @@ as_store_search_per_user (AsStore *store,
if ((flags & AS_STORE_LOAD_FLAG_DESKTOP) > 0) {
g_autofree gchar *dest = NULL;
dest = g_build_filename (g_get_user_data_dir (), "applications", NULL);
- if (!as_store_search_installed (store, flags, "user",
+ if (!as_store_search_installed (store, flags, AS_APP_SCOPE_USER,
dest, cancellable, error))
return FALSE;
}
@@ -2867,7 +2869,6 @@ static void
as_store_path_data_free (AsStorePathData *path_data)
{
g_free (path_data->arch);
- g_free (path_data->id_prefix);
g_slice_free (AsStorePathData, path_data);
}