about summary refs log tree commit diff
path: root/src/libstore/store.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/store.cc')
-rw-r--r--src/libstore/store.cc22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/libstore/store.cc b/src/libstore/store.cc
index a3e98f69691d..693a388b3e1e 100644
--- a/src/libstore/store.cc
+++ b/src/libstore/store.cc
@@ -176,12 +176,18 @@ void copyPath(const Path & src, const Path & dst)
 }
 
 
-bool isStorePath(const Path & path)
+bool isInStore(const Path & path)
 {
     return path[0] == '/'
         && path.compare(0, nixStore.size(), nixStore) == 0
         && path.size() >= nixStore.size() + 2
-        && path[nixStore.size()] == '/'
+        && path[nixStore.size()] == '/';
+}
+
+
+bool isStorePath(const Path & path)
+{
+    return isInStore(path)
         && path.find('/', nixStore.size() + 1) == Path::npos;
 }
 
@@ -193,6 +199,18 @@ void assertStorePath(const Path & path)
 }
 
 
+Path toStorePath(const Path & path)
+{
+    if (!isInStore(path))
+        throw Error(format("path `%1%' is not in the Nix store") % path);
+    unsigned int slash = path.find('/', nixStore.size() + 1);
+    if (slash == Path::npos)
+        return path;
+    else
+        return Path(path, 0, slash);
+}
+
+
 void canonicalisePathMetaData(const Path & path)
 {
     checkInterrupt();