diff options
author | Phaedrus Leeds <matthew.leeds@endlessm.com> | 2020-08-05 15:47:29 -0700 |
---|---|---|
committer | Alexander Larsson <alexander.larsson@gmail.com> | 2020-08-31 16:29:03 +0200 |
commit | 7cd19901963f002857392325f1614659236d364d (patch) | |
tree | 9f0fe4330f619ffbe5e3b596f24fb204a1a6f729 /tests | |
parent | 2325b814013988dde5cc63d75ecb7411a4412628 (diff) | |
download | flatpak-7cd19901963f002857392325f1614659236d364d.tar.gz |
Automatically pin explicitly installed runtimes
If a runtime is installed explicitly rather than as a dependency, pin it
so it doesn't get automatically removed when unused runtimes are being
removed. We do this because the runtime might be installed for
development or other uses.
This commit also rearranges some code in the mask and pin commands, and
adds a unit test.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-repo.sh | 13 | ||||
-rw-r--r-- | tests/testlibrary.c | 41 |
2 files changed, 51 insertions, 3 deletions
diff --git a/tests/test-repo.sh b/tests/test-repo.sh index 5c2db337..06624de8 100644 --- a/tests/test-repo.sh +++ b/tests/test-repo.sh @@ -577,6 +577,9 @@ setup_repo ok "uninstall with missing remote" +# Remove any pin of the runtime from an earlier test +${FLATPAK} ${U} pin --remove runtime/org.test.Platform/$ARCH/master 2>/dev/null || true + ${FLATPAK} ${U} list -a --columns=application > list-log assert_file_has_content list-log "org\.test\.Platform" @@ -593,9 +596,13 @@ ${FLATPAK} ${U} list -a --columns=application > list-log assert_file_has_content list-log "org\.test\.Platform" # Check that the runtime won't be removed if it's pinned -${FLATPAK} ${U} pin org.test.Platform +# (which happens during the install above) ${FLATPAK} ${U} pin > pins -assert_file_has_content pins "org\.test\.Platform" +assert_file_has_content pins "runtime/org\.test\.Platform/$ARCH/master" +NUM_PINS=$(cat pins | wc -l) +if [ $NUM_PINS -ne 1 ]; then + assert_not_reached "There should only be one pinned runtime" +fi rm pins ${FLATPAK} ${U} uninstall -y --unused @@ -604,7 +611,7 @@ ${FLATPAK} ${U} list -a --columns=application > list-log assert_file_has_content list-log "org\.test\.Platform" # Remove the pin and try again -${FLATPAK} ${U} pin --remove "org.test.Platform" +${FLATPAK} ${U} pin --remove "runtime/org.test.Platform/$ARCH/master" ${FLATPAK} ${U} uninstall -y --unused ${FLATPAK} ${U} list -a --columns=application > list-log assert_not_file_has_content list-log "org\.test\.Platform" diff --git a/tests/testlibrary.c b/tests/testlibrary.c index 4226a3a2..1f760c6e 100644 --- a/tests/testlibrary.c +++ b/tests/testlibrary.c @@ -4291,6 +4291,46 @@ test_installation_unused_refs (void) g_assert_cmpint (refs->len, ==, 0); } +static void +test_installation_unused_refs_excludes_pins (void) +{ + g_autoptr(FlatpakInstallation) inst = NULL; + g_autoptr(FlatpakTransaction) transaction = NULL; + g_autoptr(GPtrArray) refs = NULL; + g_autoptr(GError) error = NULL; + g_autofree char *runtime = NULL; + gboolean res; + + runtime = g_strdup_printf ("runtime/org.test.Platform/%s/master", + flatpak_get_default_arch ()); + + inst = flatpak_installation_new_user (NULL, &error); + g_assert_no_error (error); + g_assert_nonnull (inst); + + empty_installation (inst); + + transaction = flatpak_transaction_new_for_installation (inst, NULL, &error); + g_assert_no_error (error); + g_assert_nonnull (transaction); + + res = flatpak_transaction_add_install (transaction, repo_name, runtime, NULL, &error); + g_assert_no_error (error); + g_assert_true (res); + + res = flatpak_transaction_run (transaction, NULL, &error); + g_assert_no_error (error); + g_assert_true (res); + + /* Even though the runtime is unused, it shouldn't show up in + * list_unused_refs() because it was installed explicitly not as a dependency + * of an app */ + refs = flatpak_installation_list_unused_refs (inst, NULL, NULL, &error); + g_assert_nonnull (refs); + g_assert_no_error (error); + g_assert_cmpint (refs->len, ==, 0); +} + int main (int argc, char *argv[]) { @@ -4341,6 +4381,7 @@ main (int argc, char *argv[]) g_test_add_func ("/library/transaction-no-runtime", test_transaction_no_runtime); g_test_add_func ("/library/installation-no-interaction", test_installation_no_interaction); g_test_add_func ("/library/installation-unused-refs", test_installation_unused_refs); + g_test_add_func ("/library/installation-unused-refs-excludes-pins", test_installation_unused_refs_excludes_pins); global_setup (); |