From 6255938ee201b60f01fc7af44eb24bbddd83bc7e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 8 Feb 2022 16:39:06 +0000 Subject: [PATCH] dir: Use system helper to create system repo if necessary Previously, if /var/lib/flatpak didn't exist then we would use the system helper to create and populate it, but if it existed and was empty, we could only populate it if we had privileges. This led to errors from libostree: Creating repo: mkdirat: Permission denied The EnsureRepo method call is allowed by default for active local users, so do this even if allow_empty is true: this will incorporate /etc/flatpak/remotes.d into the repository, whether it is newly-created or not. This makes a `flatpak search` work immediately, without having to fetch metadata explicitly. Signed-off-by: Simon McVittie (cherry picked from commit 2489b915efae3a78ca7040c39161f8c304e4c7a5) --- common/flatpak-dir.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index 98f37464..a8cc803e 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -4005,22 +4005,33 @@ _flatpak_dir_ensure_repo (FlatpakDir *self, that still user bare-user */ OstreeRepoMode mode = OSTREE_REPO_MODE_BARE_USER_ONLY; - if (!ostree_repo_create (repo, mode, cancellable, &my_error)) + if (flatpak_dir_use_system_helper (self, NULL)) { - flatpak_rm_rf (repodir, cancellable, NULL); + if (!system_helper_maybe_ensure_repo (self, allow_empty, cancellable, error)) + return FALSE; - if (allow_empty) - return TRUE; - - g_propagate_error (error, g_steal_pointer (&my_error)); - return FALSE; + if (!ensure_repo_opened (repo, cancellable, error)) + return FALSE; } - - /* Create .changed file early to avoid polling non-existing file in monitor */ - if (!flatpak_dir_mark_changed (self, &my_error)) + else { - g_warning ("Error marking directory as changed: %s", my_error->message); - g_clear_error (&my_error); + if (!ostree_repo_create (repo, mode, cancellable, &my_error)) + { + flatpak_rm_rf (repodir, cancellable, NULL); + + if (allow_empty) + return TRUE; + + g_propagate_error (error, g_steal_pointer (&my_error)); + return FALSE; + } + + /* Create .changed file early to avoid polling non-existing file in monitor */ + if (!flatpak_dir_mark_changed (self, &my_error)) + { + g_warning ("Error marking directory as changed: %s", my_error->message); + g_clear_error (&my_error); + } } } else