summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-09-22 20:45:06 +0200
committerSven Eden <yamakuzure@gmx.net>2017-09-22 20:45:06 +0200
commit0d1efe6ec9b637291d4356925b582f743fba4c78 (patch)
tree3c0cf2613dac5b941569cabc6daee2fd33ce8d42
parent0fa84e5e28182901ddf8d7d8a76372b07ed05b07 (diff)
fileio: support writing atomic files with timestamp
Let's make sure "ts" is taken into account when writing atomic files, too.
-rw-r--r--src/basic/fileio.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index b20b12ff7..e3f3b7fc3 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -70,7 +70,13 @@ int write_string_stream_ts(FILE *f, const char *line, bool enforce_newline, stru
return fflush_and_check(f);
}
-static int write_string_file_atomic(const char *fn, const char *line, bool enforce_newline, bool do_fsync) {
+static int write_string_file_atomic(
+ const char *fn,
+ const char *line,
+ bool enforce_newline,
+ bool do_fsync,
+ struct timespec *ts) {
+
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *p = NULL;
int r;
@@ -84,10 +90,9 @@ static int write_string_file_atomic(const char *fn, const char *line, bool enfor
(void) fchmod_umask(fileno(f), 0644);
- r = write_string_stream(f, line, enforce_newline);
+ r = write_string_stream_ts(f, line, enforce_newline, ts);
if (r >= 0 && do_fsync)
r = fflush_sync_and_check(f);
-
if (r >= 0) {
if (rename(p, fn) < 0)
r = -errno;
@@ -112,8 +117,10 @@ int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags
if (flags & WRITE_STRING_FILE_ATOMIC) {
assert(flags & WRITE_STRING_FILE_CREATE);
- r = write_string_file_atomic(fn, line, !(flags & WRITE_STRING_FILE_AVOID_NEWLINE),
- flags & WRITE_STRING_FILE_SYNC);
+ r = write_string_file_atomic(fn,
+ line,
+ !(flags & WRITE_STRING_FILE_AVOID_NEWLINE),
+ flags & WRITE_STRING_FILE_SYNC, ts);
if (r < 0)
goto fail;