summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-10-19 14:03:26 +0100
committerRichard Hughes <richard@hughsie.com>2016-10-19 14:03:28 +0100
commit1fb9721311ed809ba39221720cdfbe969f5c6416 (patch)
treea83be16f3bad13a00ba2424d7e9005534b675133
parent8a08a7bb24744d54a497aee3a86a9a03ae69c40c (diff)
downloadappstream-glib-1fb9721311ed809ba39221720cdfbe969f5c6416.tar.gz
Monitor missing AppStream directories
Monitor some locations so that if they are created after the AsStore is loaded we correctly detect and load the new AppStream XML files Inspired by a patch by Joaquim Rocha <jrocha@endlessm.com>, many thanks.
-rw-r--r--libappstream-glib/as-monitor.c18
-rw-r--r--libappstream-glib/as-self-test.c4
-rw-r--r--libappstream-glib/as-store.c82
3 files changed, 53 insertions, 51 deletions
diff --git a/libappstream-glib/as-monitor.c b/libappstream-glib/as-monitor.c
index 44a8d50..b4c3681 100644
--- a/libappstream-glib/as-monitor.c
+++ b/libappstream-glib/as-monitor.c
@@ -419,14 +419,16 @@ as_monitor_add_directory (AsMonitor *monitor,
g_autoptr(GDir) dir = NULL;
/* find the files already in the directory */
- dir = g_dir_open (filename, 0, error);
- if (dir == NULL)
- return FALSE;
- while ((tmp = g_dir_read_name (dir)) != NULL) {
- g_autofree gchar *fn = NULL;
- fn = g_build_filename (filename, tmp, NULL);
- g_debug ("adding existing file: %s", fn);
- _g_ptr_array_str_add (priv->files, fn);
+ if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
+ dir = g_dir_open (filename, 0, error);
+ if (dir == NULL)
+ return FALSE;
+ while ((tmp = g_dir_read_name (dir)) != NULL) {
+ g_autofree gchar *fn = NULL;
+ fn = g_build_filename (filename, tmp, NULL);
+ g_debug ("adding existing file: %s", fn);
+ _g_ptr_array_str_add (priv->files, fn);
+ }
}
/* create new file monitor */
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index ddfb106..06801e6 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -162,11 +162,13 @@ as_test_monitor_dir_func (void)
G_CALLBACK (monitor_test_cb), &cnt_changed);
/* add watch */
- g_mkdir_with_parents (tmpdir, 0700);
ret = as_monitor_add_directory (mon, tmpdir, NULL, &error);
g_assert_no_error (error);
g_assert (ret);
+ /* create directory */
+ g_mkdir_with_parents (tmpdir, 0700);
+
/* touch file */
cmd_touch = g_strdup_printf ("touch %s", tmpfile);
ret = g_spawn_command_line_sync (cmd_touch, NULL, NULL, NULL, &error);
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c
index 467adef..c4855a3 100644
--- a/libappstream-glib/as-store.c
+++ b/libappstream-glib/as-store.c
@@ -2442,9 +2442,6 @@ as_store_load_app_info (AsStore *store,
GError **error)
{
AsStorePrivate *priv = GET_PRIVATE (store);
- const gchar *tmp;
- g_autoptr(GDir) dir = NULL;
- g_autoptr(GError) error_local = NULL;
_cleanup_uninhibit_ guint32 *tok = NULL;
/* Don't add the same dir twice, we're monitoring it for changes anyway */
@@ -2454,49 +2451,52 @@ as_store_load_app_info (AsStore *store,
/* emit once when finished */
tok = as_store_changed_inhibit (store);
- /* search all files */
- if (!g_file_test (path, G_FILE_TEST_EXISTS))
- return TRUE;
- dir = g_dir_open (path, 0, &error_local);
- if (dir == NULL) {
- if (flags & AS_STORE_LOAD_FLAG_IGNORE_INVALID) {
- g_warning ("ignoring invalid AppStream path %s: %s",
- path, error_local->message);
- return TRUE;
+ /* search all files, if the location already exists */
+ if (g_file_test (path, G_FILE_TEST_IS_DIR)) {
+ const gchar *tmp;
+ g_autoptr(GDir) dir = NULL;
+ g_autoptr(GError) error_local = NULL;
+ dir = g_dir_open (path, 0, &error_local);
+ if (dir == NULL) {
+ if (flags & AS_STORE_LOAD_FLAG_IGNORE_INVALID) {
+ g_warning ("ignoring invalid AppStream path %s: %s",
+ path, error_local->message);
+ return TRUE;
+ }
+ g_set_error (error,
+ AS_STORE_ERROR,
+ AS_STORE_ERROR_FAILED,
+ "Failed to open %s: %s",
+ path, error_local->message);
+ return FALSE;
}
- g_set_error (error,
- AS_STORE_ERROR,
- AS_STORE_ERROR_FAILED,
- "Failed to open %s: %s",
- path, error_local->message);
- return FALSE;
- }
- while ((tmp = g_dir_read_name (dir)) != NULL) {
- GError *error_store = NULL;
- g_autofree gchar *filename_md = NULL;
- if (g_strcmp0 (tmp, "icons") == 0)
- continue;
- filename_md = g_build_filename (path, tmp, NULL);
- if (!as_store_load_app_info_file (store,
- scope,
- filename_md,
- arch,
- flags,
- cancellable,
- &error_store)) {
- if (flags & AS_STORE_LOAD_FLAG_IGNORE_INVALID) {
- g_warning ("Ignoring invalid AppStream file %s: %s",
- filename_md, error_store->message);
- g_clear_error (&error_store);
- } else {
- g_propagate_error (error, error_store);
- return FALSE;
+ while ((tmp = g_dir_read_name (dir)) != NULL) {
+ GError *error_store = NULL;
+ g_autofree gchar *filename_md = NULL;
+ if (g_strcmp0 (tmp, "icons") == 0)
+ continue;
+ filename_md = g_build_filename (path, tmp, NULL);
+ if (!as_store_load_app_info_file (store,
+ scope,
+ filename_md,
+ arch,
+ flags,
+ cancellable,
+ &error_store)) {
+ if (flags & AS_STORE_LOAD_FLAG_IGNORE_INVALID) {
+ g_warning ("Ignoring invalid AppStream file %s: %s",
+ filename_md, error_store->message);
+ g_clear_error (&error_store);
+ } else {
+ g_propagate_error (error, error_store);
+ return FALSE;
+ }
}
}
}
- /* watch the directories for changes */
+ /* watch the directories for changes, even if it does not exist yet */
as_store_add_path_data (store, path, scope, arch);
if (!as_monitor_add_directory (priv->monitor,
path,
@@ -2715,8 +2715,6 @@ as_store_search_app_info (AsStore *store,
path,
supported_kinds[i],
NULL);
- if (!g_file_test (dest, G_FILE_TEST_EXISTS))
- continue;
if (!as_store_load_app_info (store, scope, dest, NULL,
flags, cancellable, error))
return FALSE;