summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2018-07-10 14:31:37 +0200
committerAlexander Larsson <alexander.larsson@gmail.com>2018-07-10 19:26:16 +0200
commit0ac154e913cc9aa687afbb8b7e55f5a340ba6d16 (patch)
treed134d622243c88d72d0eed4616c952b183a526bf
parentaecc6285d6ddc9d49cc9e90b0210d22e6f472483 (diff)
downloadflatpak-0ac154e913cc9aa687afbb8b7e55f5a340ba6d16.tar.gz
lib: Add FLATPAK_ERROR_REMOTE_NOT_FOUND error
And return it where we look up remotes. Partial fix of #1855
-rw-r--r--app/flatpak-builtins-utils.c12
-rw-r--r--common/flatpak-dir-private.h3
-rw-r--r--common/flatpak-dir.c29
-rw-r--r--common/flatpak-error.h2
-rw-r--r--common/flatpak-installation.c26
5 files changed, 34 insertions, 38 deletions
diff --git a/app/flatpak-builtins-utils.c b/app/flatpak-builtins-utils.c
index b5c0a6e5..f5765aa1 100644
--- a/app/flatpak-builtins-utils.c
+++ b/app/flatpak-builtins-utils.c
@@ -379,11 +379,8 @@ flatpak_resolve_duplicate_remotes (GPtrArray *dirs,
if (out_dir)
{
if (dirs_with_remote->len == 0)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
- "Remote \"%s\" not found", remote_name);
- return FALSE;
- }
+ return flatpak_fail_error (error, FLATPAK_ERROR_REMOTE_NOT_FOUND,
+ "Remote \"%s\" not found", remote_name);
else
*out_dir = g_object_ref (g_ptr_array_index (dirs_with_remote, chosen - 1));
}
@@ -526,7 +523,7 @@ update_appstream (GPtrArray *dirs,
{
FlatpakDir *dir = g_ptr_array_index (dirs, j);
- if (flatpak_dir_has_remote (dir, remote))
+ if (flatpak_dir_has_remote (dir, remote, NULL))
{
g_autoptr(OstreeAsyncProgress) progress = NULL;
guint64 ts_file_age;
@@ -552,7 +549,8 @@ update_appstream (GPtrArray *dirs,
}
if (!found)
- return flatpak_fail (error, _("Remote \"%s\" not found"), remote);
+ return flatpak_fail_error (error, FLATPAK_ERROR_REMOTE_NOT_FOUND,
+ _("Remote \"%s\" not found"), remote);
}
return TRUE;
diff --git a/common/flatpak-dir-private.h b/common/flatpak-dir-private.h
index 2c9b5a41..321f5ad3 100644
--- a/common/flatpak-dir-private.h
+++ b/common/flatpak-dir-private.h
@@ -636,7 +636,8 @@ char *flatpak_dir_find_remote_by_uri (FlatpakDir *self,
const char *uri,
const char *collection_id);
gboolean flatpak_dir_has_remote (FlatpakDir *self,
- const char *remote_name);
+ const char *remote_name,
+ GError **error);
char **flatpak_dir_list_remotes (FlatpakDir *self,
GCancellable *cancellable,
GError **error);
diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c
index a06c81b0..0e672864 100644
--- a/common/flatpak-dir.c
+++ b/common/flatpak-dir.c
@@ -8884,8 +8884,13 @@ _flatpak_dir_get_remote_state (FlatpakDir *self,
state->remote_name = g_strdup (remote_or_uri);
is_local = g_str_has_prefix (remote_or_uri, "file:");
- if (!is_local && !repo_get_remote_collection_id (self->repo, remote_or_uri, &state->collection_id, error))
- return NULL;
+ if (!is_local)
+ {
+ if (!flatpak_dir_has_remote (self, remote_or_uri, error))
+ return NULL;
+ if (!repo_get_remote_collection_id (self->repo, remote_or_uri, &state->collection_id, error))
+ return NULL;
+ }
if (local_only)
{
@@ -10533,20 +10538,22 @@ flatpak_dir_find_remote_by_uri (FlatpakDir *self,
gboolean
flatpak_dir_has_remote (FlatpakDir *self,
- const char *remote_name)
+ const char *remote_name,
+ GError **error)
{
GKeyFile *config = NULL;
g_autofree char *group = g_strdup_printf ("remote \"%s\"", remote_name);
- if (!flatpak_dir_maybe_ensure_repo (self, NULL, NULL))
- return FALSE;
-
- if (self->repo == NULL)
- return FALSE;
-
- config = ostree_repo_get_config (self->repo);
+ if (flatpak_dir_maybe_ensure_repo (self, NULL, NULL) &&
+ self->repo != NULL)
+ {
+ config = ostree_repo_get_config (self->repo);
+ if (config && g_key_file_has_group (config, group))
+ return TRUE;
+ }
- return g_key_file_has_group (config, group);
+ return flatpak_fail_error (error, FLATPAK_ERROR_REMOTE_NOT_FOUND,
+ "Remote \"%s\" not found", remote_name);
}
diff --git a/common/flatpak-error.h b/common/flatpak-error.h
index d822abb1..252c8a42 100644
--- a/common/flatpak-error.h
+++ b/common/flatpak-error.h
@@ -40,6 +40,7 @@ G_BEGIN_DECLS
* @FLATPAK_ERROR_ABORTED: The transaction was aborted (returned TRUE in operation-error signal).
* @FLATPAK_ERROR_SKIPPED: The App/Runtime install was skipped due to earlier errors.
* @FLATPAK_ERROR_NEED_NEW_FLATPAK: The App/Runtime needs a more recent version of flatpak.
+ * @FLATPAK_ERROR_REMOTE_NOT_FOUND: The specified remote was not found.
*
* Error codes for library functions.
*/
@@ -51,6 +52,7 @@ typedef enum {
FLATPAK_ERROR_ABORTED,
FLATPAK_ERROR_SKIPPED,
FLATPAK_ERROR_NEED_NEW_FLATPAK,
+ FLATPAK_ERROR_REMOTE_NOT_FOUND,
} FlatpakError;
#define FLATPAK_ERROR flatpak_error_quark ()
diff --git a/common/flatpak-installation.c b/common/flatpak-installation.c
index 65784284..f8375492 100644
--- a/common/flatpak-installation.c
+++ b/common/flatpak-installation.c
@@ -1494,29 +1494,17 @@ flatpak_installation_get_remote_by_name (FlatpakInstallation *self,
{
g_autoptr(FlatpakDir) dir = flatpak_installation_get_dir_maybe_no_repo (self);
g_autoptr(FlatpakDir) dir_clone = NULL;
- g_auto(GStrv) remote_names = NULL;
- int i;
- remote_names = flatpak_dir_list_remotes (dir, cancellable, error);
- if (remote_names == NULL)
+ if (!flatpak_dir_has_remote (dir, name, error))
return NULL;
- for (i = 0; remote_names[i] != NULL; i++)
- {
- if (strcmp (remote_names[i], name) == 0)
- {
- /* We clone the dir here to make sure we re-read the latest ostree repo config, in case
- it has local changes */
- dir_clone = flatpak_dir_clone (dir);
- if (!flatpak_dir_ensure_repo (dir_clone, cancellable, error))
- return NULL;
- return flatpak_remote_new_with_dir (remote_names[i], dir_clone);
- }
- }
+ /* We clone the dir here to make sure we re-read the latest ostree repo config, in case
+ it has local changes */
+ dir_clone = flatpak_dir_clone (dir);
+ if (!flatpak_dir_ensure_repo (dir_clone, cancellable, error))
+ return NULL;
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
- "No remote named '%s'", name);
- return NULL;
+ return flatpak_remote_new_with_dir (name, dir_clone);
}
/**