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"(\\$&)");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, but what's the purpose of this with raw string literals?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to escape the backslash for the regex engine, not the string parser

}

#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
'';
};
}
24 changes: 18 additions & 6 deletions tests/functional/gc-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading