From b01a52e7c65166d49f33ad49a6f30723c18b80af Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Thu, 11 Apr 2019 15:29:34 +0200 Subject: [PATCH] build-commit-from: Add support for--end-of-life-rebase=OLD=NEW This lets you rebase an app, as well as other matching refs (OLD is used as a prefix match) such as locale and debug extensions. r your changes. Lines starting Closes: #2775 Approved by: alexlarsson --- app/flatpak-builtins-build-commit-from.c | 56 ++++++++++++++++++++++++ doc/flatpak-build-commit-from.xml | 12 +++++ 2 files changed, 68 insertions(+) diff --git a/app/flatpak-builtins-build-commit-from.c b/app/flatpak-builtins-build-commit-from.c index ad878917..951ecd4a 100644 --- a/app/flatpak-builtins-build-commit-from.c +++ b/app/flatpak-builtins-build-commit-from.c @@ -45,6 +45,8 @@ static gboolean opt_force; static char **opt_gpg_key_ids; static char *opt_gpg_homedir; static char *opt_endoflife; +static char **opt_endoflife_rebase; +static char **opt_endoflife_rebase_new; static char *opt_timestamp; static char **opt_extra_collection_ids; @@ -61,6 +63,7 @@ static GOptionEntry options[] = { { "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_gpg_key_ids, N_("GPG Key ID to sign the commit with"), N_("KEY-ID") }, { "gpg-homedir", 0, 0, G_OPTION_ARG_STRING, &opt_gpg_homedir, N_("GPG Homedir to use when looking for keyrings"), N_("HOMEDIR") }, { "end-of-life", 0, 0, G_OPTION_ARG_STRING, &opt_endoflife, N_("Mark build as end-of-life"), N_("REASON") }, + { "end-of-life-rebase", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_endoflife_rebase, N_("Mark refs matching the OLDID prefix as end-of-life, to be replaced with the given NEWID"), N_("OLDID=NEWID") }, { "timestamp", 0, 0, G_OPTION_ARG_STRING, &opt_timestamp, N_("Override the timestamp of the commit (NOW for current time)"), N_("TIMESTAMP") }, { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL }, { NULL } @@ -261,6 +264,35 @@ flatpak_builtin_build_commit_from (int argc, char **argv, GCancellable *cancella if (opt_src_repo == NULL && opt_src_ref == NULL) return flatpak_fail (error, _("Either --src-repo or --src-ref must be specified.")); + /* Always create a commit if we're eol:ing, even though the app is the same */ + if (opt_endoflife != NULL || opt_endoflife_rebase != NULL) + opt_force = TRUE; + + if (opt_endoflife_rebase) + { + opt_endoflife_rebase_new = g_new0 (char *, g_strv_length (opt_endoflife_rebase)); + + for (i = 0; opt_endoflife_rebase[i] != NULL; i++) + { + char *rebase_old = opt_endoflife_rebase[i]; + char *rebase_new = strchr (rebase_old, '='); + + if (rebase_new == NULL) { + return usage_error (context, _("Invalid argument format of use --end-of-life-rebase=OLDID=NEWID"), error); + } + *rebase_new = 0; + rebase_new++; + + if (!flatpak_is_valid_name (rebase_old, error)) + return glnx_prefix_error (error, _("Invalid name %s in --end-of-life-rebase"), rebase_old); + + if (!flatpak_is_valid_name (rebase_new, error)) + return glnx_prefix_error (error, _("Invalid name %s in --end-of-life-rebase"), rebase_new); + + opt_endoflife_rebase_new[i] = rebase_new; + } + } + if (opt_timestamp) { if (!parse_datetime (&ts, opt_timestamp, NULL)) @@ -519,6 +551,10 @@ flatpak_builtin_build_commit_from (int argc, char **argv, GCancellable *cancella strcmp (key, OSTREE_COMMIT_META_KEY_ENDOFLIFE) == 0) continue; + if (opt_endoflife_rebase && + strcmp (key, OSTREE_COMMIT_META_KEY_ENDOFLIFE_REBASE) == 0) + continue; + g_variant_builder_add_value (&metadata_builder, child); } @@ -526,6 +562,26 @@ flatpak_builtin_build_commit_from (int argc, char **argv, GCancellable *cancella g_variant_builder_add (&metadata_builder, "{sv}", OSTREE_COMMIT_META_KEY_ENDOFLIFE, g_variant_new_string (opt_endoflife)); + if (opt_endoflife_rebase) + { + g_auto(GStrv) dst_ref_parts = g_strsplit (dst_ref, "/", 0); + + for (j = 0; opt_endoflife_rebase[j] != NULL; j++) + { + const char *old_prefix = opt_endoflife_rebase[j]; + + if (flatpak_has_name_prefix (dst_ref_parts[1], old_prefix)) + { + g_autofree char *new_id = g_strconcat (opt_endoflife_rebase_new[j], dst_ref_parts[1] + strlen(old_prefix), NULL); + g_autofree char *rebased_ref = g_build_filename (dst_ref_parts[0], new_id, dst_ref_parts[2], dst_ref_parts[3], NULL); + + g_variant_builder_add (&metadata_builder, "{sv}", OSTREE_COMMIT_META_KEY_ENDOFLIFE_REBASE, + g_variant_new_string (rebased_ref)); + break; + } + } + } + timestamp = ostree_commit_get_timestamp (src_commitv); if (opt_timestamp) timestamp = ts.tv_sec; diff --git a/doc/flatpak-build-commit-from.xml b/doc/flatpak-build-commit-from.xml index bc4a6715..9084fe49 100644 --- a/doc/flatpak-build-commit-from.xml +++ b/doc/flatpak-build-commit-from.xml @@ -201,6 +201,18 @@ + + + + + Mark new refs as end-of-life. Unlike , + this one takes an ID that supercedes the current one. By the user's + request, the application data may be preserved for the new application. + Note, this is actually a prefix match, so if you say org.the.app=org.new.app, + then something like org.the.app.Locale will be rebased to org.new.app.Locale. + + +