1 Cc: John Karp <johnkarp@gmail.com>
2 Subject: [PATCH 2/2] Use fsync.
4 POSIX guarantees only a successfully save after a successful call to fsync.
7 See SF Bug#2686300: http://sourceforge.net/tracker/?func=detail&aid=2686300&group_id=11005&atid=111005
14 source/file.c | 44 +++++++++++++++++++++++++++++++++++++++++---
15 util/prefFile.c | 2 ++
16 2 files changed, 43 insertions(+), 3 deletions(-)
18 diff --quilt old/source/file.c new/source/file.c
21 @@ -1029,7 +1029,17 @@ static int doSave(WindowInfo *window)
23 fwrite(fileString, sizeof(char), fileLen, fp);
27 + /* first, flush all stream buffers to the filesystem */
33 + /* second, synchronize filedata to disk */
34 + ret = fsync(fileno(fp));
38 DialogF(DF_ERR, window->shell, 1, "Error saving File",
39 @@ -1143,7 +1153,17 @@ int WriteBackupFile(WindowInfo *window)
41 fwrite(fileString, sizeof(char), fileLen, fp);
45 + /* first, flush all stream buffers to the filesystem */
51 + /* second, synchronize filedata to disk */
52 + ret = fsync(fileno(fp));
56 DialogF(DF_ERR, window->shell, 1, "Error saving Backup",
57 @@ -1308,11 +1328,19 @@ static int writeBckVersion(WindowInfo *w
61 - /* close the input and output files */
64 + /* close the input file */
69 + /* sync and close the output file */
70 + if (fdatasync(out_fd))
72 + int ret = bckError(window, errorString(), bckname);
80 @@ -1425,7 +1453,17 @@ void PrintString(const char *string, int
82 fwrite(string, sizeof(char), length, fp);
86 + /* first, flush all stream buffers to the filesystem */
92 + /* second, synchronize filedata to disk */
93 + ret = fsync(fileno(fp));
97 DialogF(DF_ERR, parent, 1, "Error while Printing",
98 diff --quilt old/util/prefFile.c new/util/prefFile.c
99 --- old/util/prefFile.c
100 +++ new/util/prefFile.c
101 @@ -297,6 +297,8 @@ int SavePreferences(Display *display, co