gzexe: ensure file always exists
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 24 Nov 2017 06:23:03 +0000 (22:23 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 24 Nov 2017 07:12:30 +0000 (23:12 -0800)
* 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.

gzexe.in

index 721aba402f5a3e843300144894c16058c82f33ad..65b2de24bcf350bfb268542c9f0646c66299eed7 100644 (file)
--- 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