about summary refs log tree commit diff
path: root/src/libstore/optimise-store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-23T19·02-0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-23T21·14-0400
commit619310571002fc74e428824bd603604d1055b61b (patch)
tree6292457190b40d41e2f5a3c2504d77edab8d4057 /src/libstore/optimise-store.cc
parent564fb7d9fa80d06397a88d69f26439727cb922c5 (diff)
Automatically optimise the Nix store when a new path is added
Auto-optimisation is enabled by default.  It can be turned off by
setting auto-optimise-store to false in nix.conf.
Diffstat (limited to 'src/libstore/optimise-store.cc')
-rw-r--r--src/libstore/optimise-store.cc22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/libstore/optimise-store.cc b/src/libstore/optimise-store.cc
index 0893db9d3130..a7aa14fb49ab 100644
--- a/src/libstore/optimise-store.cc
+++ b/src/libstore/optimise-store.cc
@@ -49,10 +49,7 @@ struct MakeImmutable
 };
 
 
-const string linksDir = ".links";
-
-
-static void hashAndLink(OptimiseStats & stats, const Path & path)
+void LocalStore::optimisePath_(OptimiseStats & stats, const Path & path)
 {
     struct stat st;
     if (lstat(path.c_str(), &st))
@@ -61,7 +58,7 @@ static void hashAndLink(OptimiseStats & stats, const Path & path)
     if (S_ISDIR(st.st_mode)) {
         Strings names = readDirectory(path);
 	foreach (Strings::iterator, i, names)
-	    hashAndLink(stats, path + "/" + *i);
+	    optimisePath_(stats, path + "/" + *i);
         return;
     }
     
@@ -91,7 +88,7 @@ static void hashAndLink(OptimiseStats & stats, const Path & path)
     printMsg(lvlDebug, format("`%1%' has hash `%2%'") % path % printHash(hash));
 
     /* Check if this is a known hash. */
-    Path linkPath = nixStore + "/" + linksDir + "/" + printHash32(hash);
+    Path linkPath = linksDir + "/" + printHash32(hash);
 
     if (!pathExists(linkPath)) {
         /* Nope, create a hard link in the links directory. */
@@ -177,15 +174,22 @@ static void hashAndLink(OptimiseStats & stats, const Path & path)
 
 void LocalStore::optimiseStore(OptimiseStats & stats)
 {
-    createDirs(nixStore + "/" + linksDir);
-
     PathSet paths = queryValidPaths();
 
     foreach (PathSet::iterator, i, paths) {
         addTempRoot(*i);
         if (!isValidPath(*i)) continue; /* path was GC'ed, probably */
         startNest(nest, lvlChatty, format("hashing files in `%1%'") % *i);
-        hashAndLink(stats, *i);
+        optimisePath_(stats, *i);
+    }
+}
+
+
+void LocalStore::optimisePath(const Path & path)
+{
+    if (queryBoolSetting("auto-optimise-store", true)) {
+        OptimiseStats stats;
+        optimisePath_(stats, path);
     }
 }