about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-01-29T12·22+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-01-29T12·22+0000
commit07ffdc28629e537c3811f86b83a93655b73909ec (patch)
tree36b10bdd8ab47d4d0098248206a87ed64b3deb28 /src/libstore
parentad529fb89fb34bea9762eccfc9c2ee6f1f2865c0 (diff)
* 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/libstore')
-rw-r--r--src/libstore/build.cc10
-rw-r--r--src/libstore/local-store.cc18
-rw-r--r--src/libstore/local-store.hh5
3 files changed, 22 insertions, 11 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index d56ae4570df7..77cffba25d8a 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -1318,18 +1318,18 @@ DerivationGoal::HookReply DerivationGoal::tryBuildHook()
         string s;
         foreach (PathSet::iterator, i, allInputs) s += *i + "\n";
         
-        writeStringToFile(inputListFN, s);
+        writeFile(inputListFN, s);
 
         /* The `outputs' file lists all outputs that have to be copied
            from the remote system. */
         s = "";
         foreach (DerivationOutputs::iterator, i, drv.outputs)
             s += i->second.path + "\n";
-        writeStringToFile(outputListFN, s);
+        writeFile(outputListFN, s);
 
         /* The `references' file has exactly the format accepted by
            `nix-store --register-validity'. */
-        writeStringToFile(referencesFN,
+        writeFile(referencesFN,
             makeValidityRegistration(allInputs, true, false));
 
         /* Tell the hook to proceed. */
@@ -1493,7 +1493,7 @@ void DerivationGoal::startBuilder()
         }
 
         /* Write closure info to `fileName'. */
-        writeStringToFile(tmpDir + "/" + fileName,
+        writeFile(tmpDir + "/" + fileName,
             makeValidityRegistration(paths, false, false));
     }
 
@@ -1570,7 +1570,7 @@ void DerivationGoal::startBuilder()
            support Samba-in-QEMU. */
         createDirs(chrootRootDir + "/etc");
 
-        writeStringToFile(chrootRootDir + "/etc/passwd",
+        writeFile(chrootRootDir + "/etc/passwd",
             (format(
                 "nixbld:x:%1%:65534:Nix build user:/:/noshell\n"
                 "nobody:x:65534:65534:Nobody:/:/noshell\n")
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 93ce8c047a7d..7c8db745cbd8 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -89,6 +89,8 @@ LocalStore::LocalStore()
     }
     if (curSchema == 1) throw Error("your Nix store is no longer supported");
     if (curSchema < nixSchemaVersion) upgradeStore12();
+
+    doFsync = queryBoolSetting("fsync-metadata", false);
 }
 
 
@@ -222,7 +224,7 @@ static Path tmpFileForAtomicUpdate(const Path & path)
 }
 
 
-static void appendReferrer(const Path & from, const Path & to, bool lock)
+void LocalStore::appendReferrer(const Path & from, const Path & to, bool lock)
 {
     Path referrersFile = referrersFileFor(from);
     
@@ -237,6 +239,8 @@ static void appendReferrer(const Path & from, const Path & to, bool lock)
     
     string s = " " + to;
     writeFull(fd, (const unsigned char *) s.c_str(), s.size());
+
+    if (doFsync) fdatasync(fd);
 }
 
 
@@ -267,6 +271,8 @@ void LocalStore::rewriteReferrers(const Path & path, bool purge, PathSet referre
     
     writeFull(fd, (const unsigned char *) s.c_str(), s.size());
 
+    if (doFsync) fdatasync(fd);
+    
     fd.close(); /* for Windows; can't rename open file */
 
     if (rename(tmpFile.c_str(), referrersFile.c_str()) == -1)
@@ -347,7 +353,7 @@ void LocalStore::registerValidPath(const ValidPathInfo & info, bool ignoreValidi
 
     /* Atomically rewrite the info file. */
     Path tmpFile = tmpFileForAtomicUpdate(infoFile);
-    writeFile(tmpFile, s);
+    writeFile(tmpFile, s, doFsync);
     if (rename(tmpFile.c_str(), infoFile.c_str()) == -1)
         throw SysError(format("cannot rename `%1%' to `%2%'") % tmpFile % infoFile);
 
@@ -737,7 +743,7 @@ Path LocalStore::addToStoreFromDump(const string & dump, const string & name,
                 StringSource source(dump);
                 restorePath(dstPath, source);
             } else
-                writeStringToFile(dstPath, dump);
+                writeFile(dstPath, dump);
 
             canonicalisePathMetaData(dstPath);
 
@@ -792,7 +798,7 @@ Path LocalStore::addTextToStore(const string & name, const string & s,
 
             if (pathExists(dstPath)) deletePathWrapped(dstPath);
 
-            writeStringToFile(dstPath, s);
+            writeFile(dstPath, s);
 
             canonicalisePathMetaData(dstPath);
             
@@ -871,7 +877,7 @@ void LocalStore::exportPath(const Path & path, bool sign,
         Path tmpDir = createTempDir();
         AutoDelete delTmp(tmpDir);
         Path hashFile = tmpDir + "/hash";
-        writeStringToFile(hashFile, printHash(hash));
+        writeFile(hashFile, printHash(hash));
 
         Path secretKey = nixConfDir + "/signing-key.sec";
         checkSecrecy(secretKey);
@@ -947,7 +953,7 @@ Path LocalStore::importPath(bool requireSignature, Source & source)
 
         if (requireSignature) {
             Path sigFile = tmpDir + "/sig";
-            writeStringToFile(sigFile, signature);
+            writeFile(sigFile, signature);
 
             Strings args;
             args.push_back("rsautl");
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index ef585fdaa8a2..31f8d91096a3 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -158,12 +158,17 @@ private:
     /* Store paths for which the referrers file must be purged. */
     PathSet delayedUpdates;
 
+    /* Whether to do an fsync() after writing Nix metadata. */
+    bool doFsync;
+
     int getSchema();
 
     void registerValidPath(const ValidPathInfo & info, bool ignoreValidity = false);
 
     ValidPathInfo queryPathInfo(const Path & path, bool ignoreErrors = false);
 
+    void appendReferrer(const Path & from, const Path & to, bool lock);
+    
     void rewriteReferrers(const Path & path, bool purge, PathSet referrers);
 
     void flushDelayedUpdates();