[ostree/wip/metalinks: 2/2] A bit of code for repo/summary
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree/wip/metalinks: 2/2] A bit of code for repo/summary
- Date: Thu, 7 Aug 2014 00:51:46 +0000 (UTC)
commit a8f20ecfd5d1ab4ef73824e7927fb70b6e2300de
Author: Colin Walters <walters verbum org>
Date: Wed Aug 6 20:51:17 2014 -0400
A bit of code for repo/summary
src/libostree/ostree-core.h | 9 +++++
src/libostree/ostree-repo.c | 70 +++++++++++++++++++++++++++++++++++++++++++
src/libostree/ostree-repo.h | 5 +++
3 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h
index a867dbe..8ed8d2d 100644
--- a/src/libostree/ostree-core.h
+++ b/src/libostree/ostree-core.h
@@ -118,6 +118,15 @@ typedef enum {
#define OSTREE_COMMIT_GVARIANT_FORMAT G_VARIANT_TYPE (OSTREE_COMMIT_GVARIANT_STRING)
/**
+ * OSTREE_SUMMARY_GVARIANT_FORMAT:
+ *
+ * a(ayay) - Array of (checksum, commit data)
+ * refs: a{s(aya{sv})} - Map of ref name -> (latest commit, additional metadata)
+ */
+#define OSTREE_SUMMARY_GVARIANT_STRING "(a(ayay)a{s(aya{sv})})"
+#define OSTREE_SUMMARY_GVARIANT_FORMAT G_VARIANT_TYPE (OSTREE_SUMMARY_GVARIANT_STRING)
+
+/**
* OstreeRepoMode:
* @OSTREE_REPO_MODE_BARE: Files are stored as themselves; can only be written as root
* @OSTREE_REPO_MODE_ARCHIVE_Z2: Files are compressed, should be owned by non-root. Can be served via HTTP
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 6f04360..cde91f2 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -2257,3 +2257,73 @@ out:
(void) gs_file_unlink (commit_tmp_path, NULL, NULL);
return ret;
}
+
+/**
+ * ostree_repo_regenerate_summary:
+ * @self: Repo
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * An OSTree repository can contain a high level "summary" file that
+ * describes the available branches and other metadata.
+ *
+ * It is not regenerated automatically when commits are created; this
+ * API is available to atomically regenerate the summary after
+ * multiple commits. It should only be invoked by one process at a
+ * time.
+ */
+gboolean
+ostree_repo_regenerate_summary (OstreeRepo *self,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ gs_unref_hashtable GHashTable *refs = NULL;
+ gs_unref_hashtable GHashTable *commits = NULL;
+ gs_unref_variant_builder GVariantBuilder *builder = NULL;
+ GList *ordered_refs = NULL;
+ GList *iter = NULL;
+ GHashTableIter hashiter;
+ gpointer hkey, hvalue;
+
+ if (!ostree_repo_list_refs (self, NULL, &refs, cancellable, error))
+ goto out;
+
+ commits = g_hash_table_new (g_str_hash, g_str_equal, g_free, g_variant_unref);
+
+ builder = g_variant_builder_new ("a(ayay)");
+
+ ordered_refs = g_hash_table_get_keys (refs);
+ ordered_refs = g_list_sort (ordered_refs, (GCompareFunc)strcmp);
+
+ for (iter = ordered_refs; iter; iter = iter->next)
+ {
+ const char *ref = iter->data;
+ const char *commit = g_hash_table_lookup (refs, ref);
+ guint8 csum[32];
+
+ g_assert (commit);
+
+ if (!g_hash_table_lookup (commits, commit))
+ {
+ gs_unref_variant GVariant *commit_content = NULL;
+
+ if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, commit,
+ &commit_content, error))
+ goto out;
+
+ g_hash_table_insert (commits, commit, g_variant_ref (commit_content));
+ }
+
+ ostree_checksum_inplace_to_bytes (commit, csum);
+
+ g_variant_builder_add (
+ }
+
+ ret = TRUE;
+ out:
+ if (ordered_refs)
+ g_list_free (ordered_refs);
+ return ret;
+}
+
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 26fd6cc..d5995f4 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -558,5 +558,10 @@ gboolean ostree_repo_verify_commit (OstreeRepo *self,
GCancellable *cancellable,
GError **error);
+gboolean ostree_repo_regenerate_summary (OstreeRepo *self,
+ GCancellable *cancellable,
+ GError **error);
+
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]