summaryrefslogtreecommitdiff
path: root/common/flatpak-installation.c
diff options
context:
space:
mode:
authorPhaedrus Leeds <matthew.leeds@endlessm.com>2020-08-05 16:05:32 -0700
committerAlexander Larsson <alexander.larsson@gmail.com>2020-08-31 16:29:03 +0200
commit097faa8411a9ac213bea3cd89c2c7acaa00e99bb (patch)
treeff90f8cb134e0ec80a9479a6aab4aff1dd2752e5 /common/flatpak-installation.c
parent7cd19901963f002857392325f1614659236d364d (diff)
downloadflatpak-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().
Diffstat (limited to 'common/flatpak-installation.c')
-rw-r--r--common/flatpak-installation.c57
1 files changed, 56 insertions, 1 deletions
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);
+}