From b6828cda310fd89e93d700c621512fa68ebe4bb8 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Aug 2017 11:17:14 +0100 Subject: [PATCH] repo-update: Disallow changing collection IDs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Emit an error message if the user tries to change the collection ID of an existing repository between two non-empty values. Allow them to set a collection ID where one was not set before. Changing the collection ID once it’s already been set will break updates for all clients who have previously pulled from the repository. If a developer really wants to change the collection ID for a repository, they’re going to have to recreate the repository from scratch. Signed-off-by: Philip Withnall --- app/flatpak-builtins-repo-update.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/flatpak-builtins-repo-update.c b/app/flatpak-builtins-repo-update.c index 36cc118e..4f991d07 100644 --- a/app/flatpak-builtins-repo-update.c +++ b/app/flatpak-builtins-repo-update.c @@ -441,9 +441,27 @@ flatpak_builtin_build_update_repo (int argc, char **argv, !flatpak_repo_set_default_branch (repo, opt_default_branch[0] ? opt_default_branch : NULL, error)) return FALSE; - if (opt_collection_id && - !flatpak_repo_set_collection_id (repo, opt_collection_id[0] ? opt_collection_id : NULL, error)) - return FALSE; + if (opt_collection_id != NULL) + { + /* Only allow a transition from no collection ID to a non-empty collection ID. + * Changing the collection ID between two different non-empty values is too + * dangerous: it will break all clients who have previously pulled from the repository. + * Require the user to recreate the repository from scratch in that case. */ +#ifdef FLATPAK_ENABLE_P2P + const char *old_collection_id = ostree_repo_get_collection_id (repo); +#else /* if !FLATPAK_ENABLE_P2P */ + const char *old_collection_id = NULL; +#endif /* !FLATPAK_ENABLE_P2P */ + const char *new_collection_id = opt_collection_id[0] ? opt_collection_id : NULL; + + if (old_collection_id != NULL && + g_strcmp0 (old_collection_id, new_collection_id) != 0) + return flatpak_fail (error, "The collection ID of an existing repository cannot be changed. " + "Recreate the repository to change or clear its collection ID."); + + if (!flatpak_repo_set_collection_id (repo, new_collection_id, error)) + return FALSE; + } if (opt_deploy_collection_id && !flatpak_repo_set_deploy_collection_id (repo, TRUE, error))