Skip to content

Commit

Permalink
Add RequireRef to pull in target app of extension
Browse files Browse the repository at this point in the history
Also refactored op_get_runtime_ref a bit. If the extension needs to run
an apply-extra script, and it specifies RequireRef, we don't need to
pull in the runtime, just the ref because the ref will pull in the
target's runtime as well.

Fixes #4566
  • Loading branch information
eeejay committed Apr 9, 2024
1 parent f16e064 commit 59ea5bc
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 15 deletions.
55 changes: 40 additions & 15 deletions common/flatpak-transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -2449,27 +2449,52 @@ find_runtime_remote (FlatpakTransaction *self,
static FlatpakDecomposed *
op_get_runtime_ref (FlatpakTransactionOperation *op)
{
g_autofree char *runtime_pref = NULL;
FlatpakDecomposed *decomposed;
FlatpakDecomposed *decomposed = NULL;
g_autoptr (GError) my_error = NULL;

if (!op->resolved_metakey)
return NULL;

/* Generally only app needs runtimes dependencies, not dependencies because you don't run extensions directly.
However if the extension has extra data (and doesn't define NoRuntime) its also needed so we can run the
apply-extra script. */
/* Apps always need runtime dependencies */
if (flatpak_decomposed_is_app (op->ref))
runtime_pref = g_key_file_get_string (op->resolved_metakey, "Application", "runtime", NULL);
else if (g_key_file_has_group (op->resolved_metakey, "Extra Data") &&
!g_key_file_get_boolean (op->resolved_metakey, "Extra Data", "NoRuntime", NULL))
runtime_pref = g_key_file_get_string (op->resolved_metakey, "ExtensionOf", "runtime", NULL);
{
g_autofree char *runtime_pref = g_key_file_get_string (
op->resolved_metakey, "Application", "runtime", NULL);
if (runtime_pref)
{
decomposed = flatpak_decomposed_new_from_pref (
FLATPAK_KINDS_RUNTIME, runtime_pref, &my_error);
}
}

if (runtime_pref == NULL)
return NULL;
if (g_key_file_has_group (op->resolved_metakey, "ExtensionOf"))
{
if (g_key_file_get_boolean (op->resolved_metakey, "ExtensionOf",
"RequireRef", NULL))
{
/* The extension requires its target to be installed */
g_autofree char *app_ref = g_key_file_get_string (
op->resolved_metakey, "ExtensionOf", "ref", NULL);
decomposed = flatpak_decomposed_new_from_ref (app_ref, &my_error);
}
else if (g_key_file_has_group (op->resolved_metakey, "Extra Data") &&
!g_key_file_get_boolean (op->resolved_metakey, "Extra Data",
"NoRuntime", NULL))
{
/* If the extension has extra data (and doesn't define NoRuntime) it
* needs a runtime so it can run the apply-extra script. */
g_autofree char *runtime_pref = g_key_file_get_string (
op->resolved_metakey, "ExtensionOf", "runtime", NULL);
if (runtime_pref)
{
decomposed = flatpak_decomposed_new_from_pref (
FLATPAK_KINDS_RUNTIME, runtime_pref, &my_error);
}
}
}

decomposed = flatpak_decomposed_new_from_pref (FLATPAK_KINDS_RUNTIME, runtime_pref, NULL);
if (decomposed == NULL)
g_info ("Invalid runtime ref %s in metadata", runtime_pref);
if (my_error != NULL)
g_info ("Cannot get decomposed dependency: %s", my_error->message);

return decomposed;
}
Expand Down Expand Up @@ -2506,7 +2531,7 @@ add_new_dep_op (FlatpakTransaction *self,

if (!ref_is_installed (self, dep_ref))
{
g_info ("Installing dependency %s of %s", flatpak_decomposed_get_pref (dep_ref),
printf ("Installing dependency %s of %s\n", flatpak_decomposed_get_pref (dep_ref),
flatpak_decomposed_get_pref (op->ref));
dep_remote = find_runtime_remote (self, op->ref, op->remote, dep_ref, op->kind, NULL, error);
if (dep_remote == NULL)
Expand Down
25 changes: 25 additions & 0 deletions tests/make-test-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,28 @@ else
fi

rm -rf ${DIR}


# build a plugin extension that pulls in app as dependency

DIR=`mktemp -d`

# Init dir
cat > ${DIR}/metadata <<EOF
[Runtime]
name=${APP_ID}.Plugin.joy
[ExtensionOf]
ref=app/$APP_ID/$ARCH/$BRANCH
RequireRef=true
EOF

mkdir -p ${DIR}/files/plug-ins/joy

flatpak build-finish ${DIR} >&2
mkdir -p repos

flatpak build-export --no-update-summary --runtime ${collection_args} ${GPGARGS-} ${EXPORT_ARGS-} ${REPO} ${DIR} ${BRANCH} >&2


rm -rf ${DIR}
49 changes: 49 additions & 0 deletions tests/test-install-extension.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
#
# Copyright (C) 2024 Eitan Isaacson <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

set -euo pipefail

. "$(dirname $0)/libtest.sh"

skip_without_bwrap
skip_revokefs_without_fuse

echo "1..3"

setup_repo "" "" master

$FLATPAK list --app ${U} > app_list
assert_not_file_has_content app_list "Hello world"

ok "App is not installed"

${FLATPAK} ${U} install -y test-repo org.test.Hello.Plugin.fun v1 >&2

$FLATPAK list ${U} | grep org.test.Hello.Plugin.fun > /dev/null
$FLATPAK list --app ${U} > app_list
assert_not_file_has_content app_list "Hello world"

ok "fun extension does not pull in app"

${FLATPAK} ${U} install -y test-repo org.test.Hello.Plugin.joy >&2

$FLATPAK list --app ${U} > app_list
assert_file_has_content app_list "Hello world"

ok "Pulled in extension's app"
1 change: 1 addition & 0 deletions tests/test-matrix/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ wrapped_tests += {'name' : 'test-unused.sh', 'script' : 'test-unused.sh'}
wrapped_tests += {'name' : 'test-prune.sh', 'script' : 'test-prune.sh'}
wrapped_tests += {'name' : 'test-seccomp.sh', 'script' : 'test-seccomp.sh'}
wrapped_tests += {'name' : 'test-repair.sh', 'script' : 'test-repair.sh'}
wrapped_tests += {'name' : 'test-install-extension.sh', 'script' : 'test-install-extension.sh'}
1 change: 1 addition & 0 deletions tests/update-test-matrix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ TEST_MATRIX_SOURCE=(
'tests/test-prune.sh' \
'tests/test-seccomp.sh' \
'tests/test-repair.sh' \
'tests/test-install-extension.sh' \
)

"${tests_srcdir}/expand-test-matrix.sh" --meson "${TEST_MATRIX_SOURCE[*]}" > "${tests_srcdir}/test-matrix/meson.build"

0 comments on commit 59ea5bc

Please sign in to comment.