[ostree] repo: Add a private helper to replace a file, honoring fsync policy



commit fff8ffdd2f20f5e16113939ac556719ebdfb24a2
Author: Colin Walters <walters verbum org>
Date:   Mon Apr 13 13:28:02 2015 -0400

    repo: Add a private helper to replace a file, honoring fsync policy
    
    Extracted from discussion in https://github.com/GNOME/ostree/pull/83

 src/libostree/ostree-repo-private.h |    9 +++++++++
 src/libostree/ostree-repo-refs.c    |    5 ++---
 src/libostree/ostree-repo.c         |   17 +++++++++++++++++
 3 files changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h
index 8b07254..ceed471 100644
--- a/src/libostree/ostree-repo-private.h
+++ b/src/libostree/ostree-repo-private.h
@@ -127,6 +127,15 @@ _ostree_repo_update_refs (OstreeRepo        *self,
                           GError           **error);
 
 gboolean      
+_ostree_repo_file_replace_contents (OstreeRepo    *self,
+                                    int            dfd,
+                                    const char    *path,
+                                    guint8        *buf,
+                                    gsize          len,
+                                    GCancellable  *cancellable,
+                                    GError       **error);
+
+gboolean      
 _ostree_repo_write_ref (OstreeRepo    *self,
                         const char    *remote,
                         const char    *ref,
diff --git a/src/libostree/ostree-repo-refs.c b/src/libostree/ostree-repo-refs.c
index a436e04..ee6db8a 100644
--- a/src/libostree/ostree-repo-refs.c
+++ b/src/libostree/ostree-repo-refs.c
@@ -106,9 +106,8 @@ write_checksum_file_at (OstreeRepo   *self,
     bufnl[l] = '\n';
     bufnl[l+1] = '\0';
 
-    if (!glnx_file_replace_contents_at (dfd, name, (guint8*)bufnl, l + 1,
-                                        self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : 
GLNX_FILE_REPLACE_DATASYNC_NEW,
-                                        cancellable, error))
+    if (!_ostree_repo_file_replace_contents (self, dfd, name, (guint8*)bufnl, l + 1,
+                                             cancellable, error))
       goto out;
   }
 
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 072ae76..b27fcce 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -1502,6 +1502,23 @@ ostree_repo_set_disable_fsync (OstreeRepo    *self,
 }
 
 
+/* Replace the contents of a file, honoring the repository's fsync
+ * policy.
+ */ 
+gboolean      
+_ostree_repo_file_replace_contents (OstreeRepo    *self,
+                                    int            dfd,
+                                    const char    *path,
+                                    guint8        *buf,
+                                    gsize          len,
+                                    GCancellable  *cancellable,
+                                    GError       **error)
+{
+  return glnx_file_replace_contents_at (dfd, path, buf, len,
+                                        self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : 
GLNX_FILE_REPLACE_DATASYNC_NEW,
+                                        cancellable, error);
+}
+
 /**
  * ostree_repo_get_path:
  * @self:


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