diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-01-29 12:22:58 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-01-29 12:22:58 +0000 |
commit | 07ffdc28629e537c3811f86b83a93655b73909ec (patch) | |
tree | 36b10bdd8ab47d4d0098248206a87ed64b3deb28 /src/libutil | |
parent | ad529fb89fb34bea9762eccfc9c2ee6f1f2865c0 (diff) | |
download | guix-07ffdc28629e537c3811f86b83a93655b73909ec.tar.gz |
* 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.
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 14 | ||||
-rw-r--r-- | src/libutil/util.hh | 6 |
2 files changed, 4 insertions, 16 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 1b86e88d7f..711a969e4f 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -15,6 +15,7 @@ #include <sys/wait.h> #include <sys/types.h> #include <fcntl.h> +#include <unistd.h> #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; diff --git a/src/libutil/util.hh b/src/libutil/util.hh index a5d0445c14..837382433a 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -62,7 +62,7 @@ string readFile(int fd); string readFile(const Path & path); /* Write a string to a file. */ -void writeFile(const Path & path, const string & s); +void writeFile(const Path & path, const string & s, bool doFsync = false); /* Read a line from a file descriptor. */ string readLine(int fd); @@ -93,10 +93,6 @@ Path createTempDir(const Path & tmpRoot = "", const Path & prefix = "nix", list of created directories, in order of creation. */ Paths createDirs(const Path & path); -/* Create a file and write the given text to it. The file is written - in binary mode (i.e., no end-of-line conversions). The path should - not already exist. */ -void writeStringToFile(const Path & path, const string & s); template<class T, class A> T singleton(const A & a) |