[ostree] repo: Don't require a txn for writing



commit f1ccaa581e3b0541fd5e9aacdae810885010bf5b
Author: Colin Walters <walters verbum org>
Date:   Mon May 26 18:32:17 2014 -0400

    repo: Don't require a txn for writing
    
    The current "transaction" symlink was introduced to fix issues with
    interrupted pulls; normally we assume that if we have a metadata
    object, we also have all objects to which it refers.
    
    There used to be a "summary" which had all the available refs, but I
    deleted it because it wasn't really used, and was still racy despite
    the transaction bits.
    
    We still want the pull process to use the transaction link, so don't
    delete the APIs, just relax the restriction on object writing, and
    introduce a new ostree_repo_set_ref_immediate().

 src/libostree/ostree-repo-commit.c  |   27 +++++++++++++++++++++++++--
 src/libostree/ostree-repo-private.h |    8 ++++++++
 src/libostree/ostree-repo-refs.c    |   30 ++++++++++++++++--------------
 src/libostree/ostree-repo.h         |    7 +++++++
 src/ostree/ot-builtin-refs.c        |   16 +++++++++-------
 5 files changed, 65 insertions(+), 23 deletions(-)
---
diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c
index 398f6ab..c3bc836 100644
--- a/src/libostree/ostree-repo-commit.c
+++ b/src/libostree/ostree-repo-commit.c
@@ -368,8 +368,6 @@ write_object (OstreeRepo         *self,
   gsize unpacked_size = 0;
   gboolean indexable = FALSE;
 
-  g_return_val_if_fail (self->in_transaction, FALSE);
-  
   if (g_cancellable_set_error_if_cancelled (cancellable, error))
     return FALSE;
 
@@ -931,6 +929,31 @@ ostree_repo_transaction_set_ref (OstreeRepo *self,
 }
 
 /**
+ * ostree_repo_set_ref_immediate:
+ * @self: An #OstreeRepo
+ * @remote: (allow-none): A remote for the ref
+ * @ref: The ref to write
+ * @checksum: The checksum to point it to
+ * @cancellable: GCancellable
+ * @error: GError
+ *
+ * This is like ostree_repo_transaction_set_ref(), except it may be
+ * invoked outside of a transaction.  This is presently safe for the
+ * case where we're creating or overwriting an existing ref.
+ */
+gboolean
+ostree_repo_set_ref_immediate (OstreeRepo *self,
+                               const char *remote,
+                               const char *ref,
+                               const char *checksum,
+                               GCancellable  *cancellable,
+                               GError       **error)
+{
+  return _ostree_repo_write_ref (self, remote, ref, checksum,
+                                 cancellable, error);
+}
+
+/**
  * ostree_repo_commit_transaction:
  * @self: An #OstreeRepo
  * @out_stats: (allow-none) (out): A set of statistics of things
diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h
index b12e116..379460a 100644
--- a/src/libostree/ostree-repo-private.h
+++ b/src/libostree/ostree-repo-private.h
@@ -122,6 +122,14 @@ _ostree_repo_update_refs (OstreeRepo        *self,
                           GCancellable      *cancellable,
                           GError           **error);
 
+gboolean      
+_ostree_repo_write_ref (OstreeRepo    *self,
+                        const char    *remote,
+                        const char    *ref,
+                        const char    *rev,
+                        GCancellable  *cancellable,
+                        GError       **error);
+
 OstreeRepoFile *
 _ostree_repo_file_new_for_commit (OstreeRepo  *repo,
                                   const char  *commit,
diff --git a/src/libostree/ostree-repo-refs.c b/src/libostree/ostree-repo-refs.c
index ba3bedb..64ae96f 100644
--- a/src/libostree/ostree-repo-refs.c
+++ b/src/libostree/ostree-repo-refs.c
@@ -570,21 +570,17 @@ ostree_repo_list_refs (OstreeRepo       *self,
   return ret;
 }
 
-static gboolean      
-write_refspec (OstreeRepo    *self,
-               const char    *refspec,
-               const char    *rev,
-               GCancellable  *cancellable,
-               GError       **error)
+gboolean      
+_ostree_repo_write_ref (OstreeRepo    *self,
+                        const char    *remote,
+                        const char    *ref,
+                        const char    *rev,
+                        GCancellable  *cancellable,
+                        GError       **error)
 {
   gboolean ret = FALSE;
-  gs_free char *remote = NULL;
-  gs_free char *name = NULL;
   gs_unref_object GFile *dir = NULL;
 
-  if (!ostree_parse_refspec (refspec, &remote, &name, error))
-    goto out;
-
   if (remote == NULL)
     dir = g_object_ref (self->local_heads_dir);
   else
@@ -600,7 +596,7 @@ write_refspec (OstreeRepo    *self,
 
   if (rev == NULL)
     {
-      gs_unref_object GFile *child = g_file_resolve_relative_path (dir, name);
+      gs_unref_object GFile *child = g_file_resolve_relative_path (dir, ref);
 
       if (g_file_query_exists (child, cancellable))
         {
@@ -610,7 +606,7 @@ write_refspec (OstreeRepo    *self,
     }
   else
     {
-      if (!write_checksum_file (dir, name, rev, cancellable, error))
+      if (!write_checksum_file (dir, ref, rev, cancellable, error))
         goto out;
     }
 
@@ -634,8 +630,14 @@ _ostree_repo_update_refs (OstreeRepo        *self,
     {
       const char *refspec = key;
       const char *rev = value;
+      gs_free char *remote = NULL;
+      gs_free char *ref = NULL;
+
+      if (!ostree_parse_refspec (refspec, &remote, &ref, error))
+        goto out;
 
-      if (!write_refspec (self, refspec, rev, cancellable, error))
+      if (!_ostree_repo_write_ref (self, remote, ref, rev,
+                                   cancellable, error))
         goto out;
     }
 
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 0ff114b..562e6c1 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -133,6 +133,13 @@ void          ostree_repo_transaction_set_ref     (OstreeRepo *self,
                                                    const char *ref,
                                                    const char *checksum);
 
+gboolean      ostree_repo_set_ref_immediate (OstreeRepo *self,
+                                             const char *remote,
+                                             const char *ref,
+                                             const char *checksum,
+                                             GCancellable  *cancellable,
+                                             GError       **error);
+
 gboolean      ostree_repo_has_object (OstreeRepo           *self,
                                       OstreeObjectType      objtype,
                                       const char           *checksum,
diff --git a/src/ostree/ot-builtin-refs.c b/src/ostree/ot-builtin-refs.c
index 3fbe571..9c291fb 100644
--- a/src/ostree/ot-builtin-refs.c
+++ b/src/ostree/ot-builtin-refs.c
@@ -67,18 +67,20 @@ ostree_builtin_refs (int argc, char **argv, OstreeRepo *repo, GCancellable *canc
     }
   else
     {
-      if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error))
-        goto out;
-
       g_hash_table_iter_init (&hashiter, refs);
       while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
         {
           const char *refspec = hashkey;
-          ostree_repo_transaction_set_refspec (repo, refspec, NULL);
-        }
+          gs_free char *remote = NULL;
+          gs_free char *ref = NULL;
 
-      if (!ostree_repo_commit_transaction (repo, NULL, cancellable, error))
-        goto out;
+          if (!ostree_parse_refspec (refspec, &remote, &ref, error))
+            goto out;
+          
+          if (!ostree_repo_set_ref_immediate (repo, remote, ref, NULL,
+                                              cancellable, error))
+            goto out;
+        }
     }
 
   ret = TRUE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]