diff options
Diffstat (limited to 'src/libstore/store-api.cc')
-rw-r--r-- | src/libstore/store-api.cc | 20 |
1 files changed, 20 insertions, 0 deletions
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 = "+-._?="; |