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 <smcv@collabora.com>
(cherry picked from commit 2489b915efae3a78ca7040c39161f8c304e4c7a5)
This commit is contained in:
Simon McVittie 2022-02-08 16:39:06 +00:00 committed by Phaedrus Leeds
parent 35ce090b9c
commit 6255938ee2

View File

@ -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