mirror of
https://github.com/flatpak/flatpak.git
synced 2026-10-21 07:05:25 -04:00
build-finish: Add --require-version and handling of it
This means that clients will refuse to install or update to your new app if the flatpak version they are using is too old.
This commit is contained in:
1 parent
a528db5b95
commit
cc85b93584
5 files changed
+88
-27
No files matched your search
@@ -35,11 +35,13 @@
|
||||
#include "flatpak-run.h"
|
||||
|
||||
static char *opt_command;
|
||||
static char *opt_require_version;
|
||||
static char **opt_extra_data;
|
||||
static gboolean opt_no_exports;
|
||||
|
||||
static GOptionEntry options[] = {
|
||||
{ "command", 0, 0, G_OPTION_ARG_STRING, &opt_command, N_("Command to set"), N_("COMMAND") },
|
||||
{ "require-version", 0, 0, G_OPTION_ARG_STRING, &opt_require_version, N_("Flatpak version to require"), N_("MAJOR.MINOR.MICRO") },
|
||||
{ "no-exports", 0, 0, G_OPTION_ARG_NONE, &opt_no_exports, N_("Don't process exports"), NULL },
|
||||
{ "extra-data", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_extra_data, N_("Extra data info"),
|
||||
N_("NAME:SHA256:DOWNLOAD-SIZE:INSTALL-SIZE:URL") },
|
||||
@@ -320,6 +322,9 @@ update_metadata (GFile *base, FlatpakContext *arg_context, GCancellable *cancell
|
||||
}
|
||||
}
|
||||
|
||||
if (opt_require_version)
|
||||
g_key_file_set_string (keyfile, "Application", "required-flatpak", opt_require_version);
|
||||
|
||||
app_context = flatpak_context_new ();
|
||||
if (!flatpak_context_load_metadata (app_context, keyfile, error))
|
||||
goto out;
|
||||
|
||||
+34
-25
@@ -92,29 +92,6 @@ dir_ref_is_installed (FlatpakDir *dir, const char *ref, char **remote_out)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static char *
|
||||
transaction_fetch_runtime_ref (FlatpakDir *dir, const char *remote, const char *ref)
|
||||
{
|
||||
g_autofree char *metadata = NULL;
|
||||
g_autoptr(GKeyFile) metakey = NULL;
|
||||
g_autofree char *runtime_ref = NULL;
|
||||
|
||||
if (!g_str_has_prefix (ref, "app/"))
|
||||
return NULL;
|
||||
|
||||
if (!flatpak_dir_fetch_ref_cache (dir, remote, ref, NULL, NULL, &metadata, NULL, NULL))
|
||||
return NULL;
|
||||
|
||||
metakey = g_key_file_new ();
|
||||
if (!g_key_file_load_from_data (metakey, metadata, -1, 0, NULL))
|
||||
return NULL;
|
||||
|
||||
runtime_ref = g_key_file_get_string (metakey, "Application", "runtime", NULL);
|
||||
|
||||
return g_steal_pointer (&runtime_ref);
|
||||
}
|
||||
|
||||
|
||||
static FlatpakTransactionOp *
|
||||
flatpak_transaction_operation_new (const char *remote,
|
||||
const char *ref,
|
||||
@@ -338,6 +315,7 @@ add_related (FlatpakTransaction *self,
|
||||
|
||||
static gboolean
|
||||
add_deps (FlatpakTransaction *self,
|
||||
GKeyFile *metakey,
|
||||
const char *remote,
|
||||
const char *ref,
|
||||
GError **error)
|
||||
@@ -347,7 +325,11 @@ add_deps (FlatpakTransaction *self,
|
||||
g_autofree char *runtime_remote = NULL;
|
||||
const char *pref;
|
||||
|
||||
runtime_ref = transaction_fetch_runtime_ref (self->dir, remote, ref);
|
||||
if (!g_str_has_prefix (ref, "app/"))
|
||||
return TRUE;
|
||||
|
||||
if (metakey)
|
||||
runtime_ref = g_key_file_get_string (metakey, "Application", "runtime", NULL);
|
||||
if (runtime_ref == NULL)
|
||||
return TRUE;
|
||||
|
||||
@@ -410,6 +392,8 @@ flatpak_transaction_add_ref (FlatpakTransaction *self,
|
||||
{
|
||||
g_autofree char *origin = NULL;
|
||||
const char *pref;
|
||||
g_autofree char *metadata = NULL;
|
||||
g_autoptr(GKeyFile) metakey = NULL;
|
||||
|
||||
pref = strchr (ref, '/') + 1;
|
||||
|
||||
@@ -440,8 +424,33 @@ flatpak_transaction_add_ref (FlatpakTransaction *self,
|
||||
}
|
||||
}
|
||||
|
||||
if (flatpak_dir_fetch_ref_cache (self->dir, remote, ref, NULL, NULL, &metadata, NULL, NULL))
|
||||
{
|
||||
metakey = g_key_file_new ();
|
||||
if (!g_key_file_load_from_data (metakey, metadata, -1, 0, NULL))
|
||||
g_clear_object (&metakey);
|
||||
}
|
||||
|
||||
if (metakey)
|
||||
{
|
||||
g_autofree char *required_version = g_key_file_get_string (metakey, "Application", "required-flatpak", NULL);
|
||||
int required_major, required_minor, required_micro;
|
||||
if (required_version)
|
||||
{
|
||||
if (sscanf (required_version, "%d.%d.%d", &required_major, &required_minor, &required_micro) != 3)
|
||||
g_print ("Invalid require-flatpak argument %s\n", required_version);
|
||||
else
|
||||
{
|
||||
if (required_major > PACKAGE_MAJOR_VERSION ||
|
||||
(required_major == PACKAGE_MAJOR_VERSION && required_minor > PACKAGE_MINOR_VERSION) ||
|
||||
(required_major == PACKAGE_MAJOR_VERSION && required_minor == PACKAGE_MINOR_VERSION && required_micro > PACKAGE_MICRO_VERSION))
|
||||
return flatpak_fail (error, _("%s needs a later flatpak version (%s)"), ref, required_version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (self->add_deps)
|
||||
add_deps (self, remote, ref, error);
|
||||
add_deps (self, metakey, remote, ref, error);
|
||||
|
||||
flatpak_transaction_add_op (self, remote, ref, subpaths, commit, !is_update, is_update);
|
||||
|
||||
|
||||
@@ -372,6 +372,9 @@ AC_SUBST(FLATPAK_MINOR_VERSION)
|
||||
AC_SUBST(FLATPAK_MICRO_VERSION)
|
||||
AC_SUBST(FLATPAK_INTERFACE_AGE)
|
||||
AC_SUBST(FLATPAK_VERSION)
|
||||
AC_DEFINE_UNQUOTED([PACKAGE_MAJOR_VERSION], $FLATPAK_MAJOR_VERSION, [Major version])
|
||||
AC_DEFINE_UNQUOTED([PACKAGE_MINOR_VERSION], $FLATPAK_MINOR_VERSION, [Minor version])
|
||||
AC_DEFINE_UNQUOTED([PACKAGE_MICRO_VERSION], $FLATPAK_MICRO_VERSION, [Micro version])
|
||||
|
||||
# libtool versioning
|
||||
#LT_RELEASE=$FLATPAK_MAJOR_VERSION.$FLATPAK_MINOR_VERSION
|
||||
|
||||
@@ -86,6 +86,14 @@
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--require-version=MAJOR.MINOR.MICRO</option></term>
|
||||
|
||||
<listitem><para>
|
||||
Require this version of later of flatpak to install/update to this build.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--share=SUBSYSTEM</option></term>
|
||||
|
||||
|
||||
+38
-2
@@ -24,7 +24,7 @@ set -euo pipefail
|
||||
skip_without_bwrap
|
||||
skip_without_user_xattrs
|
||||
|
||||
echo "1..8"
|
||||
echo "1..9"
|
||||
|
||||
setup_repo
|
||||
install_repo
|
||||
@@ -287,5 +287,41 @@ assert_has_file $FL_DIR/app/org.test.Split/$ARCH/master/active/files/e/data
|
||||
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/master/active/files/f
|
||||
assert_not_has_file $FL_DIR/app/org.test.Split/$ARCH/master/active/files/nope
|
||||
|
||||
|
||||
echo "ok subpaths"
|
||||
|
||||
VERSION=`cat "$test_builddir/package_version.txt"`
|
||||
|
||||
DIR=`mktemp -d`
|
||||
${FLATPAK} build-init ${DIR} org.test.CurrentVersion org.test.Platform org.test.Platform
|
||||
${FLATPAK} build-finish --require-version=${VERSION} --command=hello.sh ${DIR}
|
||||
${FLATPAK} build-export ${FL_GPGARGS} repo ${DIR}
|
||||
DIR=`mktemp -d`
|
||||
${FLATPAK} build-init ${DIR} org.test.OldVersion org.test.Platform org.test.Platform
|
||||
${FLATPAK} build-finish --require-version=0.6.10 --command=hello.sh ${DIR}
|
||||
${FLATPAK} build-export ${FL_GPGARGS} repo ${DIR}
|
||||
DIR=`mktemp -d`
|
||||
${FLATPAK} build-init ${DIR} org.test.NewVersion org.test.Platform org.test.Platform
|
||||
${FLATPAK} build-finish --require-version=${VERSION}9 --command=hello.sh ${DIR}
|
||||
${FLATPAK} build-export ${FL_GPGARGS} repo ${DIR}
|
||||
|
||||
update_repo
|
||||
|
||||
${FLATPAK} ${U} install test-repo org.test.OldVersion master
|
||||
${FLATPAK} ${U} install test-repo org.test.CurrentVersion master
|
||||
(! ${FLATPAK} ${U} install test-repo org.test.NewVersion master)
|
||||
|
||||
DIR=`mktemp -d`
|
||||
${FLATPAK} build-init ${DIR} org.test.OldVersion org.test.Platform org.test.Platform
|
||||
${FLATPAK} build-finish --require-version=99.0.0 --command=hello.sh ${DIR}
|
||||
${FLATPAK} build-export ${FL_GPGARGS} repo ${DIR}
|
||||
|
||||
(! ${FLATPAK} ${U} update org.test.OldVersion)
|
||||
|
||||
DIR=`mktemp -d`
|
||||
${FLATPAK} build-init ${DIR} org.test.OldVersion org.test.Platform org.test.Platform
|
||||
${FLATPAK} build-finish --require-version=0.1.1 --command=hello.sh ${DIR}
|
||||
${FLATPAK} build-export ${FL_GPGARGS} repo ${DIR}
|
||||
|
||||
${FLATPAK} ${U} update org.test.OldVersion
|
||||
|
||||
echo "ok version checks"
|
||||
Reference in new issue
Block a user