Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libstore/gc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
36 changes: 24 additions & 12 deletions tests/functional/gc-runtime.nix
Original file line number Diff line number Diff line change
@@ -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 <<EOF
#! ${shell}
sleep 10000
EOF
open = mkDerivation {
name = "gc-runtime-open";
buildCommand = "mkdir $out; echo open > $out/open";
};

chmod +x $out/program
'';
program = mkDerivation {
name = "gc-runtime-program";
builder =
# Test inline source file definitions.
builtins.toFile "builder.sh" ''
mkdir $out

cat > $out/program << 'EOF'
#! ${shell}
sleep 10000 < "$1"
EOF

chmod +x $out/program
'';
};
}
30 changes: 16 additions & 14 deletions tests/functional/gc-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,34 @@ esac

set -m # enable job control, needed for kill

TODO_NixOS

profiles="$NIX_STATE_DIR"/profiles
rm -rf "$profiles"

nix-env -p "$profiles/test" -f ./gc-runtime.nix -i gc-runtime

outPath=$(nix-env -p "$profiles/test" -q --no-name --out-path gc-runtime)
echo "$outPath"
programPath=$(nix-build --no-link ./gc-runtime.nix -A program)
environPath=$(nix-build --no-link ./gc-runtime.nix -A environ)
openPath=$(nix-build --no-link ./gc-runtime.nix -A open)

echo "backgrounding program..."
"$profiles"/test/program &
export environPath
"$programPath"/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" --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
Loading