transaction: Preinstall from first remote with ref

We could previously just assume that the first enabled remote
(potentially matching the collection ID) contains the ref, but that
obviously is not always the case.

The change here looks up the remote state of the remotes to figure out
if they actually contain the ref, and adds the first matching remote to
the transaction.
This commit is contained in:
Sebastian Wick 2025-10-29 19:56:38 +01:00
parent f61d931da8
commit 842472d234
2 changed files with 38 additions and 4 deletions

View File

@ -3185,8 +3185,9 @@ flatpak_transaction_add_sync_preinstalled (FlatpakTransaction *self,
for (int j = 0; remotes[j] != NULL; j++)
{
const char *remote = remotes[j];
g_autoptr(GError) local_error = NULL;
g_autoptr(FlatpakRemoteState) state = NULL;
g_autofree char *remote_collection_id = NULL;
g_autoptr(GError) local_error = NULL;
if (flatpak_dir_get_remote_disabled (priv->dir, remote))
continue;
@ -3194,11 +3195,29 @@ flatpak_transaction_add_sync_preinstalled (FlatpakTransaction *self,
remote_collection_id = flatpak_dir_get_remote_collection_id (priv->dir,
remote);
/* Choose the first match if the collection ID was not specified */
if (config->collection_id != NULL &&
g_strcmp0 (remote_collection_id, config->collection_id) != 0)
continue;
state = flatpak_transaction_ensure_remote_state (self,
FLATPAK_TRANSACTION_OPERATION_INSTALL,
remote,
priv->default_arch,
&local_error);
if (state == NULL)
{
g_warning ("Checking if preinstall ref %s is in remote %s failed: %s",
flatpak_decomposed_get_ref (config->ref),
remote,
local_error->message);
continue;
}
if (!flatpak_remote_state_lookup_ref (state,
flatpak_decomposed_get_ref (config->ref),
NULL, NULL, NULL, NULL, NULL, NULL))
continue;
g_info ("Adding preinstall of %s from remote %s",
flatpak_decomposed_get_ref (config->ref),
remote);

View File

@ -63,6 +63,10 @@ Install=false
Install=true
EOF
cat << EOF > hello-3.preinstall
[Flatpak Preinstall org.test.Hello3]
EOF
# Set up the runtimes
# org.test.Platform//master and org.test.Platform//devel
# and the apps
@ -76,8 +80,9 @@ make_updated_app test org.test.Collection.test devel HELLO2_DEVEL org.test.Hello
setup_repo test2
make_updated_app test2 org.test.Collection.test2 master HELLO2_MASTER_C2 org.test.Hello2
make_updated_app test2 org.test.Collection.test2 master HELLO2_MASTER_C3 org.test.Hello3
echo "1..10"
echo "1..11"
# just checking that the test remote got added
port=$(cat httpd-port)
@ -251,4 +256,14 @@ cp bad.preinstall $FLATPAK_CONFIG_DIR/preinstall.d/
${FLATPAK} ${U} preinstall -y > nothingtodo
assert_file_has_content nothingtodo "Nothing to do"
ok "bad config"
ok "bad config"
# Hello3 is in the second repo. Make sure we still manage to install it.
cp hello-3.preinstall $FLATPAK_CONFIG_DIR/preinstall.d/
${FLATPAK} ${U} preinstall -y >&2
${FLATPAK} ${U} list --columns=ref > list-log
assert_file_has_content list-log "^org\.test\.Hello3/.*/master$"
ok "app not in first repo"