diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 12a76e0865e..a80ee212b50 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -339,7 +339,7 @@ static void readProcLink(const std::filesystem::path & file, UncheckedRoots & ro static std::string quoteRegexChars(const std::string & raw) { static auto specialRegex = boost::regex(R"([.^$\\*+?()\[\]{}|])"); - return boost::regex_replace(raw, specialRegex, R"(\$&)"); + return boost::regex_replace(raw, specialRegex, R"(\\$&)"); } #ifdef __linux__ diff --git a/tests/functional/gc-runtime.nix b/tests/functional/gc-runtime.nix index ee5980bdff9..10dc5e29f56 100644 --- a/tests/functional/gc-runtime.nix +++ b/tests/functional/gc-runtime.nix @@ -1,17 +1,29 @@ with import ./config.nix; -mkDerivation { - name = "gc-runtime"; - builder = - # Test inline source file definitions. - builtins.toFile "builder.sh" '' - mkdir $out +{ + environ = mkDerivation { + name = "gc-runtime-environ"; + buildCommand = "mkdir $out; echo environ > $out/environ"; + }; - cat > $out/program < $out/program << 'EOF' + #! ${shell} + sleep 10000 < "$1" + EOF + + chmod +x $out/program + ''; + }; } diff --git a/tests/functional/gc-runtime.sh b/tests/functional/gc-runtime.sh index 0cccaaf16ab..44f88c3c46c 100755 --- a/tests/functional/gc-runtime.sh +++ b/tests/functional/gc-runtime.sh @@ -16,27 +16,39 @@ TODO_NixOS profiles="$NIX_STATE_DIR"/profiles rm -rf "$profiles" -nix-env -p "$profiles/test" -f ./gc-runtime.nix -i gc-runtime +nix-env -p "$profiles/test" -f ./gc-runtime.nix -i gc-runtime-{program,environ,open} -outPath=$(nix-env -p "$profiles/test" -q --no-name --out-path gc-runtime) -echo "$outPath" +programPath=$(nix-env -p "$profiles/test" -q --no-name --out-path gc-runtime-program) +environPath=$(nix-env -p "$profiles/test" -q --no-name --out-path gc-runtime-environ) +openPath=$(nix-env -p "$profiles/test" -q --no-name --out-path gc-runtime-open) echo "backgrounding program..." -"$profiles"/test/program & +export environPath +"$profiles"/test/program "$openPath"/open & sleep 2 # hack - wait for the program to get started child=$! echo PID=$child -nix-env -p "$profiles/test" -e gc-runtime +nix-env -p "$profiles/test" -e gc-runtime-{program,environ,open} nix-env -p "$profiles/test" --delete-generations old nix-store --gc kill -- -$child -if ! test -e "$outPath"; then +if ! test -e "$programPath"; then echo "running program was garbage collected!" exit 1 fi +if ! test -e "$environPath"; then + echo "file in environment variable was garbage collected!" + exit 1 +fi + +if ! test -e "$openPath"; then + echo "opened file was garbage collected!" + exit 1 +fi + exit 0