patchShebangs: fix crash on read-only files
Fixes a regression introduced by c1cc6ff0c0680ae6d8228953ebba93c131e04775 where patchShebangs would crash if a file is read-only
This commit is contained in:
parent
f2f55c5267
commit
2029515f40
@ -72,12 +72,25 @@ patchShebangs() {
|
|||||||
_sponge() {
|
_sponge() {
|
||||||
local content
|
local content
|
||||||
local target
|
local target
|
||||||
|
local restoreReadOnly
|
||||||
content=""
|
content=""
|
||||||
target="$1"
|
target="$1"
|
||||||
|
|
||||||
|
# Make file writable if it is read-only
|
||||||
|
if [[ ! -w "$target" ]]; then
|
||||||
|
chmod +w "$target"
|
||||||
|
restoreReadOnly=true
|
||||||
|
fi
|
||||||
|
|
||||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||||
content+="$line"$'\n'
|
content+="$line"$'\n'
|
||||||
done
|
done
|
||||||
printf '%s' "$content" > "$target"
|
printf '%s' "$content" > "$target"
|
||||||
|
|
||||||
|
# Restore read-only if it was read-only before
|
||||||
|
if [[ -n "${restoreReadOnly:-}" ]]; then
|
||||||
|
chmod -w "$target"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
local f
|
local f
|
||||||
|
Loading…
x
Reference in New Issue
Block a user