lib/commit: (refactor) Clean up delta bare write API
authorColin Walters <walters@verbum.org>
Fri, 13 Oct 2017 21:40:16 +0000 (17:40 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 18 Oct 2017 14:07:55 +0000 (14:07 +0000)
The way `_ostree_repo_open_content_bare()` did both looking for the object and
possibly creating a new fd was just weird and inconsistent with e.g. the pull
code where we always call `has_object()` first.

Just call `has_object()` in the delta paths that used this too, making the
implementation right now a thin wrapper around
`glnx_open_tmpfile_linkable_at()`, but this is prep for a later patch which does
more.

Closes: #1283
Approved by: jlebon

src/libostree/ostree-repo-commit.c
src/libostree/ostree-repo-private.h
src/libostree/ostree-repo-static-delta-processing.c

index e1649c1dd24401fba80593e9c0fc64e23145742c..eb5f92a41d4a42152ae247be8132d105d332ef41 100644 (file)
@@ -404,31 +404,18 @@ add_size_index_to_metadata (OstreeRepo        *self,
   return g_variant_ref_sink (g_variant_builder_end (builder));
 }
 
-/* Combines a check for whether or not we already have the object with
- * allocating a tempfile if we don't.  Used by the static delta code.
+/* Create a tmpfile for writing a bare file.  Currently just used
+ * by the static delta code, but will likely later be extended
+ * to be used also by the dfd_iter commit path.
  */
 gboolean
 _ostree_repo_open_content_bare (OstreeRepo          *self,
                                 const char          *checksum,
                                 guint64              content_len,
                                 GLnxTmpfile         *out_tmpf,
-                                gboolean            *out_have_object,
                                 GCancellable        *cancellable,
                                 GError             **error)
 {
-  gboolean have_obj;
-  if (!_ostree_repo_has_loose_object (self, checksum, OSTREE_OBJECT_TYPE_FILE, &have_obj,
-                                      cancellable, error))
-    return FALSE;
-  /* Do we already have this object? */
-  *out_have_object = have_obj;
-  if (have_obj)
-    {
-      /* Make sure the tempfile is unset */
-      out_tmpf->initialized = 0;
-      return TRUE;
-    }
-
   return glnx_open_tmpfile_linkable_at (self->tmp_dir_fd, ".", O_WRONLY|O_CLOEXEC,
                                         out_tmpf, error);
 }
index bbbb700e31e5cef121e34545a93fa49133cf02b7..d8d16e1a533e3a26713c0c81129b182c1f02763b 100644 (file)
@@ -370,7 +370,6 @@ _ostree_repo_open_content_bare (OstreeRepo          *self,
                                 const char          *checksum,
                                 guint64              content_len,
                                 GLnxTmpfile         *out_tmpf,
-                                gboolean            *out_have_object,
                                 GCancellable        *cancellable,
                                 GError             **error);
 
index fac377ec6f86206e4de89401993dd4a9d38b3745..7517046edb1fde5bcecd61ab5e9e41525b0d954f 100644 (file)
@@ -583,15 +583,18 @@ dispatch_open_splice_and_close (OstreeRepo                 *repo,
       if (S_ISREG (state->mode) &&
           _ostree_repo_mode_is_bare (repo->mode))
         {
-          if (!_ostree_repo_open_content_bare (repo, state->checksum,
-                                               state->content_size,
-                                               &state->tmpf,
-                                               &state->have_obj,
-                                               cancellable, error))
+          if (!ostree_repo_has_object (repo, OSTREE_OBJECT_TYPE_FILE, state->checksum,
+                                       &state->have_obj, cancellable, error))
             goto out;
 
           if (!state->have_obj)
             {
+              if (!_ostree_repo_open_content_bare (repo, state->checksum,
+                                                   state->content_size,
+                                                   &state->tmpf,
+                                                   cancellable, error))
+                goto out;
+
               state->content_out = g_unix_output_stream_new (state->tmpf.fd, FALSE);
               if (!handle_untrusted_content_checksum (repo, state, cancellable, error))
                 goto out;
@@ -682,14 +685,19 @@ dispatch_open (OstreeRepo                 *repo,
   if (state->stats_only)
     return TRUE; /* Early return */
 
-  if (!_ostree_repo_open_content_bare (repo, state->checksum,
-                                       state->content_size,
-                                       &state->tmpf,
-                                       &state->have_obj,
-                                       cancellable, error))
+  if (!ostree_repo_has_object (repo, OSTREE_OBJECT_TYPE_FILE, state->checksum,
+                               &state->have_obj, cancellable, error))
     return FALSE;
+
   if (!state->have_obj)
-    state->content_out = g_unix_output_stream_new (state->tmpf.fd, FALSE);
+    {
+      if (!_ostree_repo_open_content_bare (repo, state->checksum,
+                                           state->content_size,
+                                           &state->tmpf,
+                                           cancellable, error))
+        return FALSE;
+      state->content_out = g_unix_output_stream_new (state->tmpf.fd, FALSE);
+    }
 
   if (!handle_untrusted_content_checksum (repo, state, cancellable, error))
     return FALSE;