From f2dbaecf8696b3be77de6def2d2342b3e8f24238 Mon Sep 17 00:00:00 2001 From: Robert McQueen Date: Tue, 11 Jul 2017 13:33:17 +0100 Subject: [PATCH] allow remote add to succeed when offline Updating the metadata at the end of adding a remote means that it fails if we're offline, even if we have the .flatpakrepo file available. Unlike the other error cases in the process, which mean the operation really has messed up, the remote is actually usable even if the metadata update fails, because future operations will grab the summary and any new metadata - so we should change this to a warning to allow the operation to succeed when we're offline. https://github.com/flatpak/flatpak/issues/917 --- app/flatpak-builtins-add-remote.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/flatpak-builtins-add-remote.c b/app/flatpak-builtins-add-remote.c index 82912fe37..dbb8a42a2 100644 --- a/app/flatpak-builtins-add-remote.c +++ b/app/flatpak-builtins-add-remote.c @@ -290,6 +290,7 @@ flatpak_builtin_add_remote (int argc, char **argv, g_autoptr(GKeyFile) config = NULL; g_autoptr(GBytes) gpg_data = NULL; gboolean changed = FALSE; + g_autoptr(GError) local_error = NULL; context = g_option_context_new (_("NAME LOCATION - Add a remote repository")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); @@ -361,8 +362,23 @@ flatpak_builtin_add_remote (int argc, char **argv, return FALSE; /* We can't retrieve the extra metadata until the remote has been added locally, since - ostree_repo_remote_fetch_summary() works with the repository's name, not its URL. */ - return flatpak_dir_update_remote_configuration (dir, remote_name, cancellable, error); + ostree_repo_remote_fetch_summary() works with the repository's name, not its URL. + Don't propagate IO failed errors here because we might just be offline - the + remote should already be usable. */ + if (!flatpak_dir_update_remote_configuration (dir, remote_name, cancellable, &local_error)) + { + if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_FAILED)) + { + g_printerr (_("Warning: Could not update extra metadata for '%s': %s\n"), remote_name, local_error->message); + } + else + { + g_propagate_error (error, g_steal_pointer (&local_error)); + return FALSE; + } + } + + return TRUE; } gboolean