diff options
-rw-r--r-- | libappstream-glib/as-monitor.c | 18 | ||||
-rw-r--r-- | libappstream-glib/as-self-test.c | 4 | ||||
-rw-r--r-- | libappstream-glib/as-store.c | 82 |
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; |