diff options
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/gc.cc | 6 | ||||
-rw-r--r-- | src/libstore/store.cc | 22 | ||||
-rw-r--r-- | src/libstore/store.hh | 5 |
3 files changed, 28 insertions, 5 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 6f09e9cb7852..020712368f52 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -60,7 +60,7 @@ void createSymlink(const Path & link, const Path & target, bool careful) /* Remove the old symlink. */ if (pathExists(link)) { - if (careful && (!isLink(link) || !isStorePath(readLink(link)))) + if (careful && (!isLink(link) || !isInStore(readLink(link)))) throw Error(format("cannot create symlink `%1%'; already exists") % link); unlink(link.c_str()); } @@ -250,10 +250,10 @@ static void findRoots(const Path & path, bool recurseSymlinks, string target = readLink(path); Path target2 = absPath(target, dirOf(path)); - if (isStorePath(target2)) { + if (isInStore(target2)) { debug(format("found root `%1%' in `%2%'") % target2 % path); - roots.insert(target2); + roots.insert(toStorePath(target2)); } else if (recurseSymlinks) { 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(); diff --git a/src/libstore/store.hh b/src/libstore/store.hh index 95c738ed1bcc..1f2b630e106c 100644 --- a/src/libstore/store.hh +++ b/src/libstore/store.hh @@ -63,8 +63,13 @@ void registerValidPath(const Transaction & txn, /* Throw an exception if `path' is not directly in the Nix store. */ void assertStorePath(const Path & path); +bool isInStore(const Path & path); bool isStorePath(const Path & path); +/* 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); + /* "Fix", or canonicalise, the meta-data of the files in a store path after it has been built. In particular: - the last modification date on each file is set to 0 (i.e., |