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

[augeas-devel] augeas: master - * src/transform.c (transform_save): properly sync data to disk



Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=82de286de036512771faee4e47ec442f6778c0ee
Commit:        82de286de036512771faee4e47ec442f6778c0ee
Parent:        0341d73af287a4647be08bcee43f3560a935da8d
Author:        David Lutterkort <lutter redhat com>
AuthorDate:    Thu Mar 12 22:56:47 2009 -0700
Committer:     David Lutterkort <lutter redhat com>
CommitterDate: Thu Mar 12 22:56:47 2009 -0700

* src/transform.c (transform_save): properly sync data to disk

Make sure the data we write into the .augnew file hits the disk before
renaming to the proper name
---
 configure.ac    |    2 +-
 src/transform.c |   36 ++++++++++++++++++++++++++++++++----
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index f6951a1..bdd2d79 100644
--- a/configure.ac
+++ b/configure.ac
@@ -82,7 +82,7 @@ AC_SUBST(VERSION_SCRIPT_FLAGS)
 
 gl_INIT
 
-AC_CHECK_FUNCS([strerror_r])
+AC_CHECK_FUNCS([strerror_r fsync])
 
 AC_OUTPUT(Makefile \
           gnulib/lib/Makefile \
diff --git a/src/transform.c b/src/transform.c
index 991f654..9aa95bc 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -499,11 +499,19 @@ static int clone_file(const char *from, const char *to,
         *err_status = "clone_read";
         goto done;
     }
-
+    if (fflush(to_fp) != 0) {
+        *err_status = "clone_flush";
+        goto done;
+    }
+    if (fsync(fileno(to_fp)) < 0) {
+        *err_status = "clone_sync";
+        goto done;
+    }
     result = 0;
  done:
     fclose(from_fp);
-    fclose(to_fp);
+    if (fclose(to_fp) != 0)
+        result = -1;
     if (result != 0)
         unlink(to);
     if (result == 0)
@@ -621,15 +629,35 @@ int transform_save(struct augeas *aug, struct transform *xform,
         }
     }
     if (augorig_exists) {
-        if (transfer_file_attrs(augorig_canon, augnew, &err_status) != 0)
+        if (transfer_file_attrs(augorig_canon, augnew, &err_status) != 0) {
+            err_status = "xfer_attrs";
             goto done;
+        }
     }
 
     if (tree != NULL)
         lns_put(fp, xform->lens, tree->children, text, &err);
 
-    if (ferror (fp) || fclose(fp) != 0)
+    if (ferror(fp)) {
+        err_status = "error_augnew";
+        goto done;
+    }
+
+    if (fflush(fp) != 0) {
+        err_status = "flush_augnew";
         goto done;
+    }
+
+    if (fsync(fileno(fp)) < 0) {
+        err_status = "sync_augnew";
+        goto done;
+    }
+
+    if (fclose(fp) != 0) {
+        err_status = "close_augnew";
+        goto done;
+    }
+
     fp = NULL;
 
     if (err != NULL) {



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