about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/gc.cc9
-rw-r--r--src/libstore/store-api.cc20
-rw-r--r--src/libstore/store-api.hh10
3 files changed, 34 insertions, 5 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index c0acbab38a43..dab2b80aad06 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -26,7 +26,7 @@ static string gcLockName = "gc.lock";
 static string tempRootsDir = "temproots";
 static string gcRootsDir = "gcroots";
 
-const unsigned int defaultGcLevel = 1000;
+static const int defaultGcLevel = 1000;
 
 
 /* Acquire the global GC lock.  This is used to prevent new Nix
@@ -447,7 +447,7 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
         queryBoolSetting("gc-keep-outputs", false);
     bool gcKeepDerivations =
         queryBoolSetting("gc-keep-derivations", true);
-    unsigned int gcKeepOutputsThreshold = 
+    int gcKeepOutputsThreshold = 
         queryIntSetting ("gc-keep-outputs-threshold", defaultGcLevel);
 
     /* Acquire the global GC root.  This prevents
@@ -503,13 +503,12 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
 
 		string gcLevelStr = drv.env["__gcLevel"];
 		int gcLevel;
-		if (!string2Int(gcLevelStr,gcLevel)) {
+		if (!string2Int(gcLevelStr, gcLevel))
 		    gcLevel = defaultGcLevel;
-		}
 		
 		if (gcLevel >= gcKeepOutputsThreshold)    
 		    for (DerivationOutputs::iterator j = drv.outputs.begin();
-		            j != drv.outputs.end(); ++j)
+                         j != drv.outputs.end(); ++j)
 			if (store->isValidPath(j->second.path))
 			    computeFSClosure(j->second.path, livePaths);
             }
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 9eb313da01ff..22a66ccabdb2 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -48,6 +48,26 @@ Path toStorePath(const Path & path)
 }
 
 
+Path followLinksToStore(const Path & _path)
+{
+    Path path = absPath(_path);
+    while (!isInStore(path)) {
+        if (!isLink(path)) break;
+        string target = readLink(path);
+        path = absPath(target, dirOf(path));
+    }
+    if (!isInStore(path))
+        throw Error(format("path `%1%' is not in the Nix store") % path);
+    return path;
+}
+
+
+Path followLinksToStorePath(const Path & path)
+{
+    return toStorePath(followLinksToStore(path));
+}
+
+
 void checkStoreName(const string & name)
 {
     string validChars = "+-._?=";
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index f133302b2f84..e44259ddaf09 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -174,11 +174,21 @@ bool isStorePath(const Path & path);
 
 void checkStoreName(const string & name);
 
+
 /* Chop off the parts after the top-level store name, e.g.,
    /nix/store/abcd-foo/bar => /nix/store/abcd-foo. */
 Path toStorePath(const Path & path);
 
 
+/* Follow symlinks until we end up with a path in the Nix store. */
+Path followLinksToStore(const Path & path);
+
+
+/* Same as followLinksToStore(), but apply toStorePath() to the
+   result. */
+Path followLinksToStorePath(const Path & path);
+
+
 /* Constructs a unique store path name. */
 Path makeStorePath(const string & type,
     const Hash & hash, const string & suffix);