stdenv/patchShebangs: avoid temporary time reference file

less commands -> faster
This commit is contained in:
Jörg Thalheim 2020-08-04 06:52:56 +01:00
parent cb1654ff92
commit 6e3f4c9079
No known key found for this signature in database
GPG Key ID: 003F2096411B5F92

View File

@ -88,17 +88,15 @@ patchShebangs() {
newInterpreterLine=${newInterpreterLine%${newInterpreterLine##*[![:space:]]}}
if [[ -n "$oldPath" && "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]]; then
if [[ -n "$newPath" ]] && [[ "$newPath" != "$oldPath" ]]; then
if [[ -n "$newPath" && "$newPath" != "$oldPath" ]]; then
echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
# escape the escape chars so that sed doesn't interpret them
escapedInterpreterLine=${newInterpreterLine//\\/\\\\}
# Preserve times, see: https://github.com/NixOS/nixpkgs/pull/33281
timestamp=$(mktemp)
touch -r "$f" "$timestamp"
timestamp=$(stat --printf "%y" "$f")
sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f"
touch -r "$timestamp" "$f"
rm "$timestamp"
touch --date "$timestamp" "$f"
fi
fi
done < <(find "$@" -type f -perm -0100 -print0)