patchShebangs: preserve times, resolves #33084

Close #33281.  Edits by vcunat:
 - use Eelco's idea: empty file instead of full copy
 - use longer name suffix to decrease the likelihood of collision
This commit is contained in:
Yegor Timoshenko 2018-01-01 17:05:46 +00:00 committed by Vladimír Čunát
parent ba6e0ae33d
commit 4b1b6ee6d1
No known key found for this signature in database
GPG key ID: E747DF1F9575A3AA

View file

@ -54,7 +54,11 @@ patchShebangs() {
echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
# escape the escape chars so that sed doesn't interpret them
escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g')
# Preserve times, see: https://github.com/NixOS/nixpkgs/pull/33281
touch -r "$f" "$f.timestamp"
sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f"
touch -r "$f.timestamp" "$f"
rm "$f.timestamp"
fi
fi
done