]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
install-sh: new option -S SUFFIX for simple file backups.
authorKarl Berry <karl@freefriends.org>
Fri, 13 Nov 2020 01:49:31 +0000 (17:49 -0800)
committerKarl Berry <karl@freefriends.org>
Fri, 13 Nov 2020 01:49:31 +0000 (17:49 -0800)
* lib/install-sh: implement and document -S.
Patch sent by Julien Elie:
        https://lists.gnu.org/archive/html/automake-patches/2018-03/msg00004.html
(scriptversion): 2020-11-13.01
* t/install-sh-option-S.sh: new test.
* t/list-of-tests.mk (handwritten_tests): add it.
* NEWS: mention it.

NEWS
lib/install-sh
t/install-sh-option-S.sh [new file with mode: 0644]
t/list-of-tests.mk

diff --git a/NEWS b/NEWS
index a6d283f7ab6034b8423a2ea1a5ad1c9359959a1e..83f793551ee0993b3d1a1702cae7ab59a2819068 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -93,7 +93,8 @@ New in ?.?.?:
 * Miscellaneous changes
 
   - install-sh tweaks:
-    . new option to preserve mtime, i.e., invoke cp -p.
+    . new option -p to preserve mtime, i.e., invoke cp -p.
+    . new option -S SUFFIX to attempt backup files using SUFFIX.
     . no longer unconditionally uses -f when rm is overridden by RMPROG.
     . does not chown existing directories.
 
index b6d2a909d1b6e755df6a4b550d0f881d14c2ec6b..bf704a45273375a93093fb1d2fcd7d389d24e356 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # install - install a program, script, or datafile
 
-scriptversion=2020-11-11.03; # UTC
+scriptversion=2020-11-13.01; # UTC
 
 # This originates from X11R5 (mit/util/scripts/install.sh), which was
 # later released in X11R6 (xc/config/util/install.sh) with the
@@ -73,6 +73,7 @@ mode=0755
 # This is like GNU 'install' as of coreutils 8.32 (2020).
 mkdir_umask=22
 
+backupsuffix=
 chgrpcmd=
 chmodcmd=$chmodprog
 chowncmd=
@@ -110,6 +111,7 @@ Options:
   -o USER       $chownprog installed files to USER.
   -p            pass -p to $cpprog.
   -s            $stripprog installed files.
+  -S SUFFIX     attempt to back up existing files, with suffix SUFFIX.
   -t DIRECTORY  install into DIRECTORY.
   -T            report an error if DSTFILE is a directory.
 
@@ -120,6 +122,8 @@ Environment variables override the default commands:
 By default, rm is invoked with -f; when overridden with RMPROG,
 it's up to you to specify -f if you want it.
 
+If -S is not specified, no backups are attempted.
+
 Email bug reports to bug-automake@gnu.org.
 Automake home page: https://www.gnu.org/software/automake/
 "
@@ -152,6 +156,9 @@ while test $# -ne 0; do
 
     -s) stripcmd=$stripprog;;
 
+    -S) backupsuffix="$2"
+        shift;;
+
     -t)
         is_target_a_directory=always
         dst_arg=$2
@@ -486,6 +493,13 @@ do
     then
       rm -f "$dsttmp"
     else
+      # If $backupsuffix is set, and the file being installed
+      # already exists, attempt a backup.  Don't worry if it fails,
+      # e.g., if mv doesn't support -f.
+      if test -n "$backupsuffix" && test -f "$dst"; then
+        $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null
+      fi
+      
       # Rename the file to the real destination.
       $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
 
diff --git a/t/install-sh-option-S.sh b/t/install-sh-option-S.sh
new file mode 100644 (file)
index 0000000..991741b
--- /dev/null
@@ -0,0 +1,30 @@
+#! /bin/sh
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+# More install-sh checks: option -S SUFFIX should create backups.
+
+required=non-root
+. test-init.sh
+
+get_shell_script install-sh
+
+# File gets backed up if -S is specified.
+echo foo >file
+echo bar >newfile
+./install-sh -S .BAK newfile file
+test -r file.BAK
+
+:
index 5359c22421491d319735c996cdbde3ac7c645376..1a3bb986d122c355d55c56d12af642ade391b71a 100644 (file)
@@ -531,6 +531,7 @@ t/installdir.sh \
 t/add-missing-install-sh.sh \
 t/install-sh-unittests.sh \
 t/install-sh-option-C.sh \
+t/install-sh-option-S.sh \
 t/instdat.sh \
 t/instdat2.sh \
 t/instdir.sh \