mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-24 22:50:49 +00:00
fdada4a45f
This introduces extra escaping for $NIX_STORE that gets interpolated into a PCRE. The escaping is performed using a standard Perl function "quotemeta" (see "perldoc -f quotemeta" for reference). The same value is also used in sed regex which uses POSIX basic regular expressions instead of PCRE, so it needs fewer characters to be escaped. It should not cause much problem to not change sed invocation, but I replace it with equivalent Perl expression (actually the behavior is changed to not output a newline character after the matched output).
30 lines
811 B
Bash
30 lines
811 B
Bash
source $stdenv/setup
|
|
|
|
mkdir -p $out/bin
|
|
cat > $out/bin/nuke-refs <<EOF
|
|
#! $SHELL -e
|
|
|
|
excludes=""
|
|
while getopts e: o; do
|
|
case "\$o" in
|
|
e) storeId=\$(echo "\$OPTARG" | $perl/bin/perl -ne "print \"\\\$1\" if m|^\Q$NIX_STORE\E/([a-z0-9]{32})-.*|")
|
|
if [ -z "\$storeId" ]; then
|
|
echo "-e argument must be a Nix store path"
|
|
exit 1
|
|
fi
|
|
excludes="\$excludes(?!\$storeId)"
|
|
;;
|
|
esac
|
|
done
|
|
shift \$((\$OPTIND-1))
|
|
|
|
for i in "\$@"; do
|
|
if test ! -L "\$i" -a -f "\$i"; then
|
|
cat "\$i" | $perl/bin/perl -pe "s|\Q$NIX_STORE\E/\$excludes[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" > "\$i.tmp"
|
|
if test -x "\$i"; then chmod +x "\$i.tmp"; fi
|
|
mv "\$i.tmp" "\$i"
|
|
fi
|
|
done
|
|
EOF
|
|
chmod +x $out/bin/nuke-refs
|