[ostree] repo: new function ostree_repo_prune_static_deltas
- From: Giuseppe Scrivano <gscrivano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] repo: new function ostree_repo_prune_static_deltas
- Date: Fri, 18 Dec 2015 10:22:10 +0000 (UTC)
commit 6b1e495a7aac2527f91208274867df52d5ca935f
Author: Giuseppe Scrivano <gscrivan redhat com>
Date: Tue Dec 15 10:32:25 2015 +0100
repo: new function ostree_repo_prune_static_deltas
Extract existing code from ostree_repo_prune and add an argument COMMIT,
that controls which commit purge. If not set, the old behavior is kept.
Signed-off-by: Giuseppe Scrivano <gscrivan redhat com>
src/libostree/ostree-repo-prune.c | 115 ++++++++++++++++++++++++-------------
src/libostree/ostree-repo.h | 5 ++
2 files changed, 79 insertions(+), 41 deletions(-)
---
diff --git a/src/libostree/ostree-repo-prune.c b/src/libostree/ostree-repo-prune.c
index 86949f3..166e67e 100644
--- a/src/libostree/ostree-repo-prune.c
+++ b/src/libostree/ostree-repo-prune.c
@@ -113,6 +113,78 @@ maybe_prune_loose_object (OtPruneData *data,
}
/**
+ * ostree_repo_prune_static_deltas:
+ * @self: Repo
+ * @commit: (allow-none): ASCII SHA256 checksum for commit, or %NULL for each
+ * non existing commit
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Prune static deltas, if COMMIT is specified then delete static delta files only
+ * targeting that commit; otherwise any static delta of non existing commits are
+ * deleted.
+ */
+gboolean
+ostree_repo_prune_static_deltas (OstreeRepo *self, const char *commit,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ g_autoptr(GPtrArray) deltas = NULL;
+ guint i;
+
+ if (!ostree_repo_list_static_delta_names (self, &deltas,
+ cancellable, error))
+ goto out;
+
+ for (i = 0; i < deltas->len; i++)
+ {
+ const char *deltaname = deltas->pdata[i];
+ const char *dash = strchr (deltaname, '-');
+ const char *to = NULL;
+ gboolean have_commit;
+ g_autofree char *from = NULL;
+ g_autofree char *deltadir = NULL;
+
+ if (!dash)
+ {
+ to = deltaname;
+ }
+ else
+ {
+ from = g_strndup (deltaname, dash - deltaname);
+ to = dash + 1;
+ }
+
+ if (commit)
+ {
+ if (g_strcmp0 (to, commit))
+ continue;
+ }
+ else
+ {
+ if (!ostree_repo_has_object (self, OSTREE_OBJECT_TYPE_COMMIT,
+ to, &have_commit,
+ cancellable, error))
+ goto out;
+
+ if (have_commit)
+ continue;
+ }
+
+ deltadir = _ostree_get_relative_static_delta_path (from, to, NULL);
+
+ if (!gs_shutil_rm_rf_at (self->repo_dir_fd, deltadir,
+ cancellable, error))
+ goto out;
+ }
+
+ ret = TRUE;
+ out:
+ return ret;
+}
+
+/**
* ostree_repo_prune:
* @self: Repo
* @flags: Options controlling prune process
@@ -220,47 +292,8 @@ ostree_repo_prune (OstreeRepo *self,
goto out;
}
- { g_autoptr(GPtrArray) deltas = NULL;
- guint i;
-
- if (!ostree_repo_list_static_delta_names (self, &deltas,
- cancellable, error))
- goto out;
-
- for (i = 0; i < deltas->len; i++)
- {
- const char *deltaname = deltas->pdata[i];
- const char *dash = strchr (deltaname, '-');
- const char *to = NULL;
- gboolean have_commit;
- g_autofree char *from = NULL;
- g_autofree char *deltadir = NULL;
-
- if (!dash)
- {
- to = deltaname;
- }
- else
- {
- from = g_strndup (deltaname, dash - deltaname);
- to = dash + 1;
- }
-
- if (!ostree_repo_has_object (self, OSTREE_OBJECT_TYPE_COMMIT,
- to, &have_commit,
- cancellable, error))
- goto out;
-
- if (have_commit)
- continue;
-
- deltadir = _ostree_get_relative_static_delta_path (from, to, NULL);
-
- if (!gs_shutil_rm_rf_at (self->repo_dir_fd, deltadir,
- cancellable, error))
- goto out;
- }
- }
+ if (!ostree_repo_prune_static_deltas (self, NULL, cancellable, error))
+ goto out;
ret = TRUE;
*out_objects_total = (data.n_reachable_meta + data.n_unreachable_meta +
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 51a4075..1680de8 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -691,6 +691,11 @@ typedef enum {
OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY
} OstreeRepoPruneFlags;
+gboolean
+ostree_repo_prune_static_deltas (OstreeRepo *self, const char *commit,
+ GCancellable *cancellable,
+ GError **error);
+
gboolean ostree_repo_prune (OstreeRepo *self,
OstreeRepoPruneFlags flags,
gint depth,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]