mirror of
https://github.com/flatpak/flatpak.git
synced 2026-02-01 11:31:21 -05:00
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().
This commit is contained in:
committed by
Alexander Larsson
parent
7cd1990196
commit
097faa8411
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user