diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-09-22 20:59:39 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-09-22 20:59:39 +0200 |
commit | c95480b3cff1bae5f2feab1ab3cbca79277908fa (patch) | |
tree | f9d3b88841ccdaaea861f00609f6406e0050096c /src/basic | |
parent | f1bc0ab56b810492193914b409012386d4119348 (diff) |
fileio: move fsync() logic into write_string_stream_ts()
That way, write_string_stream_ts() becomes more powerful, and we can
remove duplicate code from write_string_file_atomic() and
write_string_file_ts().
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/fileio.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 65d63a0ff..d5751a3b5 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -72,7 +72,10 @@ int write_string_stream_ts( return -errno; } - return fflush_and_check(f); + if (flags & WRITE_STRING_FILE_SYNC) + return fflush_sync_and_check(f); + else + return fflush_and_check(f); } static int write_string_file_atomic( @@ -95,16 +98,18 @@ static int write_string_file_atomic( (void) fchmod_umask(fileno(f), 0644); r = write_string_stream_ts(f, line, flags, ts); - if (r >= 0 && (flags & WRITE_STRING_FILE_SYNC)) - r = fflush_sync_and_check(f); - if (r >= 0) { - if (rename(p, fn) < 0) - r = -errno; + if (r < 0) + goto fail; + + if (rename(p, fn) < 0) { + r = -errno; + goto fail; } - if (r < 0) - (void) unlink(p); + return 0; +fail: + (void) unlink(p); return r; } @@ -163,12 +168,6 @@ int write_string_file_ts( if (r < 0) goto fail; - if (flags & WRITE_STRING_FILE_SYNC) { - r = fflush_sync_and_check(f); - if (r < 0) - return r; - } - return 0; fail: |