From 07ffdc28629e537c3811f86b83a93655b73909ec Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 29 Jan 2010 12:22:58 +0000 Subject: * Added an option "fsync-metadata" to fsync() changes to /nix/var/nix/db. * Removed the function writeStringToFile since it does (almost) the same thing as writeFile. --- src/libutil/util.cc | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'src/libutil/util.cc') diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 1b86e88d7ff3..711a969e4fc9 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include "util.hh" @@ -220,12 +221,13 @@ string readFile(const Path & path) } -void writeFile(const Path & path, const string & s) +void writeFile(const Path & path, const string & s, bool doFsync) { AutoCloseFD fd = open(path.c_str(), O_WRONLY | O_TRUNC | O_CREAT, 0666); if (fd == -1) throw SysError(format("opening file `%1%'") % path); writeFull(fd, (unsigned char *) s.c_str(), s.size()); + if (doFsync) fdatasync(fd); } @@ -413,16 +415,6 @@ Paths createDirs(const Path & path) } -void writeStringToFile(const Path & path, const string & s) -{ - AutoCloseFD fd(open(path.c_str(), - O_CREAT | O_EXCL | O_WRONLY, 0666)); - if (fd == -1) - throw SysError(format("creating file `%1%'") % path); - writeFull(fd, (unsigned char *) s.c_str(), s.size()); -} - - LogType logType = ltPretty; Verbosity verbosity = lvlInfo; -- cgit 1.4.1