[ostree] repo: Delete .commitmeta file on empty metadata



commit 5a3300fe5b84e0b00223391c415db4501964f30f
Author: Matthew Barnes <mbarnes redhat com>
Date:   Thu Mar 12 21:17:34 2015 -0400

    repo: Delete .commitmeta file on empty metadata
    
    The API docs for ostree_repo_write_commit_detached_metadata() were
    written as though it already behaved that way.
    
    https://bugzilla.gnome.org/746123

 src/libostree/ostree-repo-commit.c |   41 +++++++++++++++++++++++++++++-------
 1 files changed, 33 insertions(+), 8 deletions(-)
---
diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c
index 8ea7d76..ce5aa07 100644
--- a/src/libostree/ostree-repo-commit.c
+++ b/src/libostree/ostree-repo-commit.c
@@ -1970,21 +1970,46 @@ ostree_repo_write_commit_detached_metadata (OstreeRepo      *self,
   gs_unref_object GFile *metadata_path =
     _ostree_repo_get_commit_metadata_loose_path (self, checksum);
   gs_unref_variant GVariant *normalized = NULL;
+  gsize normalized_size = 0;
 
   if (!_ostree_repo_ensure_loose_objdir_at (self->objects_dir_fd, checksum,
                                             cancellable, error))
     goto out;
 
-  normalized = g_variant_get_normal_form (metadata);
+  if (metadata != NULL)
+    {
+      normalized = g_variant_get_normal_form (metadata);
+      normalized_size = g_variant_get_size (normalized);
+    }
 
-  if (!g_file_replace_contents (metadata_path,
-                                g_variant_get_data (normalized),
-                                g_variant_get_size (normalized),
-                                NULL, FALSE, 0, NULL,
-                                cancellable, error))
+  if (normalized_size == 0)
     {
-      g_prefix_error (error, "Unable to write detached metadata: ");
-      goto out;
+      GError *local_error = NULL;
+
+      (void) g_file_delete (metadata_path, cancellable, &local_error);
+
+      if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+        {
+          g_clear_error (&local_error);
+        }
+      else if (local_error != NULL)
+        {
+          g_propagate_error (error, local_error);
+          g_prefix_error (error, "Unable to delete detached metadata: ");
+          goto out;
+        }
+    }
+  else
+    {
+      if (!g_file_replace_contents (metadata_path,
+                                    g_variant_get_data (normalized),
+                                    g_variant_get_size (normalized),
+                                    NULL, FALSE, 0, NULL,
+                                    cancellable, error))
+        {
+          g_prefix_error (error, "Unable to write detached metadata: ");
+          goto out;
+        }
     }
 
   ret = TRUE;


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