From 00802cc710e82ebb1eda006c95b5ffe7138f9678 Mon Sep 17 00:00:00 2001 From: Joaquim Rocha Date: Mon, 19 Jun 2017 12:38:54 +0200 Subject: [PATCH] Re-create the cache repo if it is not bare-user We need to re-create the cache repo if it has not been previously configured as bare-user, so it avoids permissions related issues. --- common/flatpak-dir.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index 944132ba..42fd1293 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -4897,6 +4897,8 @@ flatpak_dir_create_system_child_repo (FlatpakDir *self, g_autoptr(OstreeRepo) new_repo = NULL; g_autoptr(GKeyFile) config = NULL; OstreeRepoMode mode = OSTREE_REPO_MODE_BARE_USER; + const char *mode_str = "bare-user"; + g_autofree char *current_mode = NULL; const char *mode_env = g_getenv ("FLATPAK_OSTREE_REPO_MODE"); g_assert (!self->user); @@ -4922,8 +4924,10 @@ flatpak_dir_create_system_child_repo (FlatpakDir *self, new_repo = ostree_repo_new (repo_dir); /* Allow to override the mode when user-only is needed (e.g. live systems) */ - if (g_strcmp0 (mode_env, "user-only") == 0) + if (g_strcmp0 (mode_env, "user-only") == 0) { mode = OSTREE_REPO_MODE_BARE_USER_ONLY; + mode_str = "bare-user-only"; + } repo_dir_config = g_file_get_child (repo_dir, "config"); if (!g_file_query_exists (repo_dir_config, NULL)) @@ -4942,8 +4946,28 @@ flatpak_dir_create_system_child_repo (FlatpakDir *self, } } - /* Ensure the config is updated */ config = ostree_repo_copy_config (new_repo); + + /* Verify that the mode is the expected one; if it isn't, recreate the repo */ + current_mode = g_key_file_get_string (config, "core", "mode", NULL); + if (current_mode == NULL || g_strcmp0 (current_mode, mode_str) != 0) + { + flatpak_rm_rf (repo_dir, NULL, NULL); + + /* Re-initialize the object because its dir's contents have been deleted (and it + * holds internal references to them) */ + g_object_unref (new_repo); + new_repo = ostree_repo_new (repo_dir); + + if (!ostree_repo_create (new_repo, mode, NULL, error)) + return NULL; + + /* Reload the repo config */ + g_key_file_free (config); + config = ostree_repo_copy_config (new_repo); + } + + /* Ensure the config is updated */ g_key_file_set_string (config, "core", "parent", flatpak_file_get_path_cached (ostree_repo_get_path (self->repo)));