aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-02-09 09:50:29 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-02-09 09:50:29 +0000
commit582e01c06f9ecee25a31c34562926b41dc2856eb (patch)
treeddb6236f949485e3b5b960d66862c45fbdf32207 /src/libutil
parentc5474398433225e40c8868b0952aebe36da2c849 (diff)
* Automatically upgrade <= 0.7 Nix stores to the new schema (so that
existing user environments continue to work). * `nix-store --verify': detect incomplete closures.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc9
-rw-r--r--src/libutil/util.hh3
2 files changed, 12 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 2fb3e9ee6..27df7a1aa 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -185,6 +185,15 @@ string readFile(const Path & path)
}
+void writeFile(const Path & path, const string & s)
+{
+ 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());
+}
+
+
static void _deletePath(const Path & path)
{
checkInterrupt();
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index c7f117129..b67913862 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -94,6 +94,9 @@ Strings readDirectory(const Path & path);
string readFile(int fd);
string readFile(const Path & path);
+/* Write a string to a file. */
+void writeFile(const Path & path, const string & s);
+
/* Delete a path; i.e., in the case of a directory, it is deleted
recursively. Don't use this at home, kids. */
void deletePath(const Path & path);