From 633518628f48fb9c06bfd570eeca6f62696aba05 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 29 Nov 2007 16:18:24 +0000 Subject: * nix-env -e: support uninstalling by path, so that one can say $ nix-env -e $(which firefox) or $ nix-env -e /nix/store/nywzlygrkfcgz7dfmhm5xixlx1l0m60v-pan-0.132 * nix-env -i: if an argument contains a slash anywhere, treat it as a path and follow it through symlinks into the Nix store. This allows things like $ nix-build -A firefox $ nix-env -i ./result * nix-env -q/-i/-e: don't complain when the `*' selector doesn't match anything. In particular, `nix-env -q \*' doesn't fail anymore on an empty profile. --- src/libstore/store-api.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/libstore/store-api.cc') 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 = "+-._?="; -- cgit 1.4.1