POSIX guarantees only a successfully save after a successful call to fsync.
So do this.

See SF Bug#2686300: 
http://sourceforge.net/tracker/?func=detail&aid=2686300&group_id=11005&atid=111005

Regards,
Bert

---

 source/file.c   |   44 +++++++++++++++++++++++++++++++++++++++++---
 util/prefFile.c |    2 ++
 2 files changed, 43 insertions(+), 3 deletions(-)

diff --quilt old/source/file.c new/source/file.c
--- old/source/file.c
+++ new/source/file.c
@@ -1029,7 +1029,17 @@ static int doSave(WindowInfo *window)
 #else
     fwrite(fileString, sizeof(char), fileLen, fp);
     ret = ferror(fp);
+    if (0 == ret)
+    {
+        /* first, flush all stream buffers to the filesystem */
+        ret = fflush(fp);
+    }
 #endif
+    if (0 == ret)
+    {
+        /* second, synchronize filedata to disk */
+        ret = fsync(fileno(fp));
+    }
     if (0 != ret)
     {
         DialogF(DF_ERR, window->shell, 1, "Error saving File",
@@ -1143,7 +1153,17 @@ int WriteBackupFile(WindowInfo *window)
 #else
     fwrite(fileString, sizeof(char), fileLen, fp);
     ret = ferror(fp);
+    if (0 == ret)
+    {
+        /* first, flush all stream buffers to the filesystem */
+        ret = fflush(fp);
+    }
 #endif
+    if (0 == ret)
+    {
+        /* second, synchronize filedata to disk */
+        ret = fsync(fileno(fp));
+    }
     if (0 != ret)
     {
         DialogF(DF_ERR, window->shell, 1, "Error saving Backup",
@@ -1308,11 +1328,19 @@ static int writeBckVersion(WindowInfo *w
         }
     }
 
-    /* close the input and output files */
+    free(io_buffer);
+
+    /* close the input file */
     close(in_fd);
-    close(out_fd);
 
-    free(io_buffer);
+    /* sync and close the output file */
+    if (fdatasync(out_fd))
+    {
+        int ret = bckError(window, errorString(), bckname);
+        close(out_fd);
+        return ret;
+    }
+    close(out_fd);
 
 #endif /* VMS */
 
@@ -1425,7 +1453,17 @@ void PrintString(const char *string, int
 #else
     fwrite(string, sizeof(char), length, fp);
     ret = ferror(fp);
+    if (0 == ret)
+    {
+        /* first, flush all stream buffers to the filesystem */
+        ret = fflush(fp);
+    }
 #endif
+    if (0 == ret)
+    {
+        /* second, synchronize filedata to disk */
+        ret = fsync(fileno(fp));
+    }
     if (0 != ret)
     {
         DialogF(DF_ERR, parent, 1, "Error while Printing",
diff --quilt old/util/prefFile.c new/util/prefFile.c
--- old/util/prefFile.c
+++ new/util/prefFile.c
@@ -297,6 +297,8 @@ int SavePreferences(Display *display, co
            fprintf(fp, "\n");
        }
     }
+    fflush(fp);
+    fsync(fileno(fp));
     fclose(fp);
     return True;
 }
-- 
NEdit Develop mailing list - [email protected]
http://www.nedit.org/mailman/listinfo/develop

Reply via email to