summaryrefslogtreecommitdiff
path: root/gzexe.in
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-11-23 22:23:03 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2017-11-23 23:12:30 -0800
commitb06803378a7fe81e8fd9ec0cfb38c8e304a44b32 (patch)
tree0e2e6c6ff19f7e94305217d34d8ecb4237114c0d /gzexe.in
parent10d7ae8ee402d796e484b77f7da3a2c18228e298 (diff)
downloadgzip-b06803378a7fe81e8fd9ec0cfb38c8e304a44b32.tar.gz
gzexe: ensure file always exists
* gzexe.in: When in a filesystem that does not support symlinks, use rm+cp rather than mv to make backups, so that the argument file always exists.
Diffstat (limited to 'gzexe.in')
-rw-r--r--gzexe.in5
1 files changed, 4 insertions, 1 deletions
diff --git a/gzexe.in b/gzexe.in
index 721aba4..65b2de2 100644
--- a/gzexe.in
+++ b/gzexe.in
@@ -213,7 +213,10 @@ EOF
printf >&2 '%s\n' "$0: $tmp: cannot chmod"
continue
}
- ln -f "$file" "$file~" 2>/dev/null || mv -f "$file" "$file~" || {
+ ln -f "$file" "$file~" 2>/dev/null || {
+ # Hard links may not work. Fall back on rm+cp so that $file always exists.
+ rm -f "$file~" && cp -p "$file" "$file~"
+ } || {
res=$?
printf >&2 '%s\n' "$0: cannot backup $i as $i~"
continue