diff options
author | Phaedrus Leeds <matthew.leeds@endlessm.com> | 2020-08-05 16:05:32 -0700 |
---|---|---|
committer | Alexander Larsson <alexander.larsson@gmail.com> | 2020-08-31 16:29:03 +0200 |
commit | 097faa8411a9ac213bea3cd89c2c7acaa00e99bb (patch) | |
tree | ff90f8cb134e0ec80a9479a6aab4aff1dd2752e5 | |
parent | 7cd19901963f002857392325f1614659236d364d (diff) | |
download | flatpak-097faa8411a9ac213bea3cd89c2c7acaa00e99bb.tar.gz |
uninstall: Note pinned runtimes in --unused output
When "flatpak uninstall --unused" is run, we don't remove unused
runtimes that are pinned. List them in the output so the user knows they
are being left installed.
This commit also adds new library API,
flatpak_installation_list_pinned_refs().
-rw-r--r-- | app/flatpak-builtins-uninstall.c | 19 | ||||
-rw-r--r-- | common/flatpak-installation.c | 57 | ||||
-rw-r--r-- | common/flatpak-installation.h | 4 |
3 files changed, 78 insertions, 2 deletions
diff --git a/app/flatpak-builtins-uninstall.c b/app/flatpak-builtins-uninstall.c index f5959f93..74a59930 100644 --- a/app/flatpak-builtins-uninstall.c +++ b/app/flatpak-builtins-uninstall.c @@ -220,14 +220,31 @@ flatpak_builtin_uninstall (int argc, char **argv, GCancellable *cancellable, GEr g_autoptr(FlatpakInstallation) installation = NULL; UninstallDir *udir; g_autoptr(GPtrArray) unused = NULL; + g_autoptr(GPtrArray) pinned = NULL; flatpak_dir_maybe_ensure_repo (dir, NULL, NULL); if (flatpak_dir_get_repo (dir) == NULL) continue; + installation = flatpak_installation_new_for_dir (dir, NULL, NULL); + pinned = flatpak_installation_list_pinned_refs (installation, opt_arch, cancellable, error); + if (pinned == NULL) + return FALSE; + + if (pinned->len > 0) + { + g_print (_("\nThese runtimes in installation '%s' are pinned and won't be removed; see flatpak-pin(1):\n"), + flatpak_dir_get_name_cached (dir)); + for (i = 0; i < pinned->len; i++) + { + FlatpakInstalledRef *rref = g_ptr_array_index (pinned, i); + g_autofree char *ref = flatpak_ref_format_ref (FLATPAK_REF (rref)); + g_print (" %s\n", ref); + } + } + udir = uninstall_dir_ensure (uninstall_dirs, dir); - installation = flatpak_installation_new_for_dir (dir, NULL, NULL); unused = flatpak_installation_list_unused_refs (installation, opt_arch, cancellable, error); if (unused == NULL) return FALSE; diff --git a/common/flatpak-installation.c b/common/flatpak-installation.c index 8b2f9d69..3957d5f2 100644 --- a/common/flatpak-installation.c +++ b/common/flatpak-installation.c @@ -2926,7 +2926,8 @@ find_used_refs (FlatpakDir *dir, * * A reference is used if it is either an application, or an sdk, * or the runtime of a used ref, or an extension of a used ref. - * Pinned runtimes are also considered used; see flatpak-pin(1). + * Pinned runtimes are also considered used; see flatpak-pin(1) and + * flatpak_installation_list_pinned_refs(). * * Returns: (transfer container) (element-type FlatpakInstalledRef): a GPtrArray of * #FlatpakInstalledRef instances @@ -3046,3 +3047,57 @@ flatpak_installation_list_unused_refs (FlatpakInstallation *self, return g_steal_pointer (&refs); } + +/** + * flatpak_installation_list_pinned_refs: + * @self: a #FlatpakInstallation + * @arch: (nullable): if non-%NULL, the architecture of refs to collect + * @cancellable: (nullable): a #GCancellable + * @error: return location for a #GError + * + * Lists the installed references that are pinned, meaning they will not be + * returned by flatpak_installation_list_unused_refs() and won't be removed + * unless explicitly specified for removal. + * + * Refs appear here either because they have been pinned automatically by + * Flatpak or because the user pinned them; see flatpak-pin(1). + * + * Returns: (transfer container) (element-type FlatpakInstalledRef): a GPtrArray of + * #FlatpakInstalledRef instances + * + * Since: 1.9.0 + */ +GPtrArray * +flatpak_installation_list_pinned_refs (FlatpakInstallation *self, + const char *arch, + GCancellable *cancellable, + GError **error) +{ + g_autoptr(FlatpakDir) dir = NULL; + g_autoptr(GPtrArray) refs = NULL; + g_auto(GStrv) runtime_refs = NULL; + int i; + + dir = flatpak_installation_get_dir (self, error); + if (dir == NULL) + return NULL; + + if (!flatpak_dir_list_refs (dir, "runtime", &runtime_refs, cancellable, error)) + return NULL; + + refs = g_ptr_array_new_with_free_func (g_object_unref); + + for (i = 0; runtime_refs[i] != NULL; i++) + { + const char *ref = runtime_refs[i]; + g_auto(GStrv) parts = g_strsplit (ref, "/", -1); + + if (arch != NULL && strcmp (parts[2], arch) != 0) + continue; + + if (flatpak_dir_ref_is_pinned (dir, ref)) + g_ptr_array_add (refs, get_ref (dir, ref, NULL, NULL)); + } + + return g_steal_pointer (&refs); +} diff --git a/common/flatpak-installation.h b/common/flatpak-installation.h index 5a0fd247..9ad4f827 100644 --- a/common/flatpak-installation.h +++ b/common/flatpak-installation.h @@ -245,6 +245,10 @@ FLATPAK_EXTERN GPtrArray *flatpak_installation_list_unused_refs (Flatp const char *arch, GCancellable *cancellable, GError **error); +FLATPAK_EXTERN GPtrArray *flatpak_installation_list_pinned_refs (FlatpakInstallation *self, + const char *arch, + GCancellable *cancellable, + GError **error); FLATPAK_EXTERN FlatpakInstalledRef * flatpak_installation_get_installed_ref (FlatpakInstallation *self, FlatpakRefKind kind, const char *name, |