[ostree] sysroot: Add ostree_sysroot_prepare_cleanup()
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] sysroot: Add ostree_sysroot_prepare_cleanup()
- Date: Wed, 16 Sep 2015 13:24:02 +0000 (UTC)
commit b0bd16ec1181cee880810088e481642ae67cf037
Author: Matthew Barnes <mbarnes redhat com>
Date: Wed Sep 9 14:50:14 2015 -0400
sysroot: Add ostree_sysroot_prepare_cleanup()
New public function works like ostree_sysroot_cleanup() EXCEPT FOR
pruning the repository.
Under the hood, add _ostree_sysroot_piecemeal_cleanup() which takes
flags to better control what files are cleaned up. Both public cleanup
functions are now wrappers for _ostree_sysroot_piecemeal_cleanup() with
different flags.
doc/ostree-sections.txt | 1 +
src/libostree/ostree-sysroot-cleanup.c | 104 ++++++++++++++++++++++++++------
src/libostree/ostree-sysroot-deploy.c | 3 +
src/libostree/ostree-sysroot-private.h | 12 ++++
src/libostree/ostree-sysroot.h | 4 +
5 files changed, 105 insertions(+), 19 deletions(-)
---
diff --git a/doc/ostree-sections.txt b/doc/ostree-sections.txt
index a4d4f2e..84ba417 100644
--- a/doc/ostree-sections.txt
+++ b/doc/ostree-sections.txt
@@ -386,6 +386,7 @@ ostree_sysroot_get_booted_deployment
ostree_sysroot_get_deployment_directory
ostree_sysroot_get_deployment_origin_path
ostree_sysroot_cleanup
+ostree_sysroot_prepare_cleanup
ostree_sysroot_get_repo
ostree_sysroot_deployment_set_kargs
ostree_sysroot_write_deployments
diff --git a/src/libostree/ostree-sysroot-cleanup.c b/src/libostree/ostree-sysroot-cleanup.c
index 14a3a5e..85364cc 100644
--- a/src/libostree/ostree-sysroot-cleanup.c
+++ b/src/libostree/ostree-sysroot-cleanup.c
@@ -425,20 +425,18 @@ cleanup_ref_prefix (OstreeRepo *repo,
}
static gboolean
-generate_deployment_refs_and_prune (OstreeSysroot *self,
- OstreeRepo *repo,
- int bootversion,
- int subbootversion,
- GPtrArray *deployments,
- GCancellable *cancellable,
- GError **error)
+generate_deployment_refs (OstreeSysroot *self,
+ OstreeRepo *repo,
+ int bootversion,
+ int subbootversion,
+ GPtrArray *deployments,
+ GCancellable *cancellable,
+ GError **error)
{
gboolean ret = FALSE;
int cleanup_bootversion;
int cleanup_subbootversion;
guint i;
- gint n_objects_total, n_objects_pruned;
- guint64 freed_space;
cleanup_bootversion = (bootversion == 0) ? 1 : 0;
cleanup_subbootversion = (subbootversion == 0) ? 1 : 0;
@@ -471,10 +469,27 @@ generate_deployment_refs_and_prune (OstreeSysroot *self,
goto out;
}
+ ret = TRUE;
+ out:
+ ostree_repo_abort_transaction (repo, cancellable, NULL);
+ return ret;
+}
+
+static gboolean
+prune_repo (OstreeRepo *repo,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gint n_objects_total;
+ gint n_objects_pruned;
+ guint64 freed_space;
+ gboolean ret = FALSE;
+
if (!ostree_repo_prune (repo, OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY, 0,
&n_objects_total, &n_objects_pruned, &freed_space,
cancellable, error))
goto out;
+
if (freed_space > 0)
{
char *freed_space_str = g_format_size_full (freed_space, 0);
@@ -482,11 +497,11 @@ generate_deployment_refs_and_prune (OstreeSysroot *self,
}
ret = TRUE;
- out:
- ostree_repo_abort_transaction (repo, cancellable, NULL);
+
+out:
return ret;
}
-
+
/**
* ostree_sysroot_cleanup:
* @self: Sysroot
@@ -501,26 +516,77 @@ ostree_sysroot_cleanup (OstreeSysroot *self,
GCancellable *cancellable,
GError **error)
{
+ OstreeSysrootCleanupFlags flags;
+
+ /* Do everything. */
+ flags = OSTREE_SYSROOT_CLEANUP_ALL;
+
+ return _ostree_sysroot_piecemeal_cleanup (self, flags, cancellable, error);
+}
+
+/**
+ * ostree_sysroot_prepare_cleanup:
+ * @self: Sysroot
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Like ostree_sysroot_cleanup() in that it cleans up incomplete deployments
+ * and old boot versions, but does NOT prune the repository.
+ */
+gboolean
+ostree_sysroot_prepare_cleanup (OstreeSysroot *self,
+ GCancellable *cancellable,
+ GError **error)
+{
+ OstreeSysrootCleanupFlags flags;
+
+ /* Do everything EXCEPT pruning the repository. */
+ flags = OSTREE_SYSROOT_CLEANUP_ALL & ~OSTREE_SYSROOT_CLEANUP_PRUNE_REPO;
+
+ return _ostree_sysroot_piecemeal_cleanup (self, flags, cancellable, error);
+}
+
+gboolean
+_ostree_sysroot_piecemeal_cleanup (OstreeSysroot *self,
+ OstreeSysrootCleanupFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
gboolean ret = FALSE;
glnx_unref_object OstreeRepo *repo = NULL;
+ g_return_val_if_fail (OSTREE_IS_SYSROOT (self), FALSE);
g_return_val_if_fail (self->loaded, FALSE);
- if (!cleanup_other_bootversions (self, cancellable, error))
- goto out;
+ if (flags & OSTREE_SYSROOT_CLEANUP_BOOTVERSIONS)
+ {
+ if (!cleanup_other_bootversions (self, cancellable, error))
+ goto out;
+ }
- if (!cleanup_old_deployments (self, cancellable, error))
- goto out;
+ if (flags & OSTREE_SYSROOT_CLEANUP_DEPLOYMENTS)
+ {
+ if (!cleanup_old_deployments (self, cancellable, error))
+ goto out;
+ }
if (self->deployments->len > 0)
{
if (!ostree_sysroot_get_repo (self, &repo, cancellable, error))
goto out;
- if (!generate_deployment_refs_and_prune (self, repo, self->bootversion,
- self->subbootversion, self->deployments,
- cancellable, error))
+ if (!generate_deployment_refs (self, repo,
+ self->bootversion,
+ self->subbootversion,
+ self->deployments,
+ cancellable, error))
goto out;
+
+ if (flags & OSTREE_SYSROOT_CLEANUP_PRUNE_REPO)
+ {
+ if (!prune_repo (repo, cancellable, error))
+ goto out;
+ }
}
ret = TRUE;
diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c
index da6816a..daa8640 100644
--- a/src/libostree/ostree-sysroot-deploy.c
+++ b/src/libostree/ostree-sysroot-deploy.c
@@ -489,6 +489,9 @@ checkout_deployment_tree (OstreeSysroot *sysroot,
if (!glnx_opendirat (sysroot->sysroot_fd, osdeploy_path, TRUE, &osdeploy_dfd, error))
goto out;
+ if (!glnx_shutil_rm_rf_at (osdeploy_dfd, checkout_target_name, cancellable, error))
+ goto out;
+
if (!ostree_repo_checkout_tree_at (repo, &checkout_opts, osdeploy_dfd,
checkout_target_name, csum,
cancellable, error))
diff --git a/src/libostree/ostree-sysroot-private.h b/src/libostree/ostree-sysroot-private.h
index fa7b086..0c38e26 100644
--- a/src/libostree/ostree-sysroot-private.h
+++ b/src/libostree/ostree-sysroot-private.h
@@ -90,4 +90,16 @@ gboolean _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot,
GCancellable *cancellable,
GError **error);
+typedef enum {
+ OSTREE_SYSROOT_CLEANUP_BOOTVERSIONS = 1 << 0,
+ OSTREE_SYSROOT_CLEANUP_DEPLOYMENTS = 1 << 1,
+ OSTREE_SYSROOT_CLEANUP_PRUNE_REPO = 1 << 2,
+ OSTREE_SYSROOT_CLEANUP_ALL = 0xffff
+} OstreeSysrootCleanupFlags;
+
+gboolean _ostree_sysroot_piecemeal_cleanup (OstreeSysroot *sysroot,
+ OstreeSysrootCleanupFlags flags,
+ GCancellable *cancellable,
+ GError **error);
+
G_END_DECLS
diff --git a/src/libostree/ostree-sysroot.h b/src/libostree/ostree-sysroot.h
index 2fbc23b..88cb759 100644
--- a/src/libostree/ostree-sysroot.h
+++ b/src/libostree/ostree-sysroot.h
@@ -81,6 +81,10 @@ gboolean ostree_sysroot_cleanup (OstreeSysroot *self,
GCancellable *cancellable,
GError **error);
+gboolean ostree_sysroot_prepare_cleanup (OstreeSysroot *self,
+ GCancellable *cancellable,
+ GError **error);
+
gboolean ostree_sysroot_write_origin_file (OstreeSysroot *sysroot,
OstreeDeployment *deployment,
GKeyFile *new_origin,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]