aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-02-19 21:29:18 +0100
committerGitHub <noreply@github.com>2020-02-19 21:29:18 +0100
commit2e953b567ebbcd3aaaf71bf592ab733bdcdd6797 (patch)
treeaef1a1a947dc7bf35ff59a07e85b227cc368afe5
parent2ba67da0532c5cf3cd4797c40f0031b7cc88cc15 (diff)
parentf2a03acf3f42140f40fa5141b2b6ea94a554df64 (diff)
Merge pull request #3325 from xzfc/clean-tmpdir
nix-shell: clean up the tmpDir and escape variables
-rwxr-xr-xsrc/nix-build/nix-build.cc17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc
index e602ea555..ff95ad787 100755
--- a/src/nix-build/nix-build.cc
+++ b/src/nix-build/nix-build.cc
@@ -427,13 +427,18 @@ static void _main(int argc, char * * argv)
lose the current $PATH directories. */
auto rcfile = (Path) tmpDir + "/rc";
writeFile(rcfile, fmt(
- (keepTmp ? "" : "rm -rf '%1%'; "s) +
+ R"(_nix_shell_clean_tmpdir() { rm -rf %1%; }; )"s +
+ (keepTmp ?
+ "trap _nix_shell_clean_tmpdir EXIT; "
+ "exitHooks+=(_nix_shell_clean_tmpdir); "
+ "failureHooks+=(_nix_shell_clean_tmpdir); ":
+ "_nix_shell_clean_tmpdir; ") +
(pure ? "" : "[ -n \"$PS1\" ] && [ -e ~/.bashrc ] && source ~/.bashrc;") +
"%2%"
"dontAddDisableDepTrack=1; "
"[ -e $stdenv/setup ] && source $stdenv/setup; "
"%3%"
- "PATH=\"%4%:$PATH\"; "
+ "PATH=%4%:\"$PATH\"; "
"SHELL=%5%; "
"set +e; "
R"s([ -n "$PS1" ] && PS1='\n\[\033[1;32m\][nix-shell:\w]\$\[\033[0m\] '; )s"
@@ -442,12 +447,12 @@ static void _main(int argc, char * * argv)
"shopt -u nullglob; "
"unset TZ; %6%"
"%7%",
- (Path) tmpDir,
+ shellEscape(tmpDir),
(pure ? "" : "p=$PATH; "),
(pure ? "" : "PATH=$PATH:$p; unset p; "),
- dirOf(*shell),
- *shell,
- (getenv("TZ") ? (string("export TZ='") + getenv("TZ") + "'; ") : ""),
+ shellEscape(dirOf(*shell)),
+ shellEscape(*shell),
+ (getenv("TZ") ? (string("export TZ=") + shellEscape(getenv("TZ")) + "; ") : ""),
envCommand));
Strings envStrs;