From ee54e2b09969c6567aa26a31da5b3ecd615f601e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 12 Apr 2017 15:46:12 -0400 Subject: [PATCH] Avoid confusing behavior of flatpak info I have multiple branches of org.gnome.Platform install system-wide, and non per-user. And flatpak info gives me: flatpak info org.gnome.Platform -> not installed flatpak info --system org.gnome.Platform -> multiple branches This confusing behavior comes from the fact that we are querying multiple locations and are not careful enough to collate the errors we get properly. This commit changes things so that we keep querying the next location as long as we get a 'not installed' error, and we report the first 'multiple branches' error we get. --- app/flatpak-builtins-utils.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/app/flatpak-builtins-utils.c b/app/flatpak-builtins-utils.c index 0567f2ae..c9ec66cc 100644 --- a/app/flatpak-builtins-utils.c +++ b/app/flatpak-builtins-utils.c @@ -132,6 +132,7 @@ flatpak_find_installed_pref (const char *pref, FlatpakKinds kinds, const char *d if (search_user || search_all) { user_dir = flatpak_dir_get_user (); + ref = flatpak_dir_find_installed_ref (user_dir, id, branch, @@ -140,6 +141,12 @@ flatpak_find_installed_pref (const char *pref, FlatpakKinds kinds, const char *d &lookup_error); if (ref) dir = user_dir; + + if (g_error_matches (lookup_error, G_IO_ERROR, G_IO_ERROR_FAILED)) + { + g_propagate_error (error, g_steal_pointer (&lookup_error)); + return NULL; + } } if (ref == NULL && search_all) @@ -153,17 +160,26 @@ flatpak_find_installed_pref (const char *pref, FlatpakKinds kinds, const char *d for (i = 0; i < system_dirs->len; i++) { FlatpakDir *system_dir = g_ptr_array_index (system_dirs, i); + + g_clear_error (&lookup_error); + ref = flatpak_dir_find_installed_ref (system_dir, id, branch, arch, kinds, &kind, - lookup_error == NULL ? &lookup_error : NULL); + &lookup_error); if (ref) { dir = system_dir; break; } + + if (g_error_matches (lookup_error, G_IO_ERROR, G_IO_ERROR_FAILED)) + { + g_propagate_error (error, g_steal_pointer (&lookup_error)); + return NULL; + } } } else @@ -182,17 +198,25 @@ flatpak_find_installed_pref (const char *pref, FlatpakKinds kinds, const char *d if (installation_dir) { + g_clear_error (&lookup_error); + ref = flatpak_dir_find_installed_ref (installation_dir, id, branch, arch, kinds, &kind, - lookup_error == NULL ? &lookup_error : NULL); + &lookup_error); if (ref) { dir = installation_dir; break; } + + if (g_error_matches (lookup_error, G_IO_ERROR, G_IO_ERROR_FAILED)) + { + g_propagate_error (error, g_steal_pointer (&lookup_error)); + return NULL; + } } } } @@ -200,12 +224,16 @@ flatpak_find_installed_pref (const char *pref, FlatpakKinds kinds, const char *d if (ref == NULL && search_system) { system_dir = flatpak_dir_get_system_default (); + + g_clear_error (&lookup_error); + ref = flatpak_dir_find_installed_ref (system_dir, id, branch, arch, kinds, &kind, - lookup_error == NULL ? &lookup_error : NULL); + &lookup_error); + if (ref) dir = system_dir; }