From 6236a60a1bf5d9d64de98c59633e0a9a222967bf Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Sun, 24 Sep 2017 10:06:35 +0800 Subject: [PATCH] lib: Add methods to clean up refs in the local repository In some cases, a user might pull a ref into the local repository and not deploy it by using FLATPAK_INSTALL_FLAGS_NO_DEPLOY. Later on, that user might decide that they don't want to deploy the ref after all, but there was no way to remove that ref from the local repository in the public API, so it takes up disk space. Add flatpak_installation_remove_local_ref_sync to remove a given ref from the local repository if the ref is known and flatpak_installation_cleanup_local_refs_sync to remove all undeployed refs. Fixes #1031 Closes: #1034 Approved by: alexlarsson --- lib/flatpak-installation.c | 56 ++++++++++++++++++++++++++++++++++++++ lib/flatpak-installation.h | 9 ++++++ 2 files changed, 65 insertions(+) diff --git a/lib/flatpak-installation.c b/lib/flatpak-installation.c index 6aab5cb5..67812683 100644 --- a/lib/flatpak-installation.c +++ b/lib/flatpak-installation.c @@ -2041,3 +2041,59 @@ flatpak_installation_list_installed_related_refs_sync (FlatpakInstallation *self return g_steal_pointer (&refs); } + +/** + * flatpak_installation_remove_local_ref_sync + * @self: a #FlatpakInstallation + * @remote_name: the name of the remote + * @ref: the ref + * @cancellable: (nullable): a #GCancellable + * @error: return location for a #GError + * + * Remove the OSTree ref given by @remote_name:@ref from the local flatpak + * repository. The next time the underlying OSTree repo is pruned, objects + * which were attached to that ref will be removed. This is useful if you + * pulled a flatpak ref using flatpak_installation_install_full() and + * specified %FLATPAK_INSTALL_FLAGS_NO_DEPLOY but then decided not to + * deploy the ref later on and want to remove the local ref to prevent it + * from taking up disk space. + * + * Returns: %TRUE on success + */ +gboolean +flatpak_installation_remove_local_ref_sync (FlatpakInstallation *self, + const char *remote_name, + const char *ref, + GCancellable *cancellable, + GError **error) +{ + g_autoptr(FlatpakDir) dir = flatpak_installation_get_dir (self); + + return flatpak_dir_remove_ref (dir, remote_name, ref, cancellable, error); +} + +/** + * flatpak_installation_cleanup_local_refs_sync + * @self: a #FlatpakInstallation + * @cancellable: (nullable): a #GCancellable + * @error: return location for a #GError + * + * Remove all OSTree refs from the local flatpak repository which are not + * in a deployed state. The next time the underlying OSTree repo is pruned, + * objects which were attached to that ref will be removed. This is useful if + * you pulled a flatpak refs using flatpak_installation_install_full() and + * specified %FLATPAK_INSTALL_FLAGS_NO_DEPLOY but then decided not to + * deploy the refs later on and want to remove the local refs to prevent them + * from taking up disk space. + * + * Returns: %TRUE on success + */ +gboolean +flatpak_installation_cleanup_local_refs_sync (FlatpakInstallation *self, + GCancellable *cancellable, + GError **error) +{ + g_autoptr(FlatpakDir) dir = flatpak_installation_get_dir (self); + + return flatpak_dir_cleanup_undeployed_refs (dir, cancellable, error); +} diff --git a/lib/flatpak-installation.h b/lib/flatpak-installation.h index 1e0a8627..706184c0 100644 --- a/lib/flatpak-installation.h +++ b/lib/flatpak-installation.h @@ -309,4 +309,13 @@ FLATPAK_EXTERN GPtrArray * flatpak_installation_list_installed_related_ref GCancellable *cancellable, GError **error); +FLATPAK_EXTERN gboolean flatpak_installation_remove_local_ref_sync (FlatpakInstallation *self, + const char *remote_name, + const char *ref, + GCancellable *cancellable, + GError **error); +FLATPAK_EXTERN gboolean flatpak_installation_cleanup_local_refs_sync (FlatpakInstallation *self, + GCancellable *cancellable, + GError **error); + #endif /* __FLATPAK_INSTALLATION_H__ */