automake-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[automake-commit] branch master updated: install-sh: new option -S SUFFI


From: Karl Berry
Subject: [automake-commit] branch master updated: install-sh: new option -S SUFFIX for simple file backups.
Date: Thu, 12 Nov 2020 20:49:46 -0500

This is an automated email from the git hooks/post-receive script.

karl pushed a commit to branch master
in repository automake.

View the commit online:
https://git.savannah.gnu.org/gitweb/?p=automake.git;a=commitdiff;h=db65189f8022ac9084bf9e6a311a42edd175b6be

The following commit(s) were added to refs/heads/master by this push:
     new db65189  install-sh: new option -S SUFFIX for simple file backups.
db65189 is described below

commit db65189f8022ac9084bf9e6a311a42edd175b6be
Author: Karl Berry <karl@freefriends.org>
AuthorDate: Thu Nov 12 17:49:31 2020 -0800

    install-sh: new option -S SUFFIX for simple file backups.
    
    * 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                     |  3 ++-
 lib/install-sh           | 16 +++++++++++++++-
 t/install-sh-option-S.sh | 30 ++++++++++++++++++++++++++++++
 t/list-of-tests.mk       |  1 +
 4 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index a6d283f..83f7935 100644
--- 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.
 
diff --git a/lib/install-sh b/lib/install-sh
index b6d2a90..bf704a4 100755
--- a/lib/install-sh
+++ b/lib/install-sh
@@ -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
index 0000000..991741b
--- /dev/null
+++ b/t/install-sh-option-S.sh
@@ -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
+
+:
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index 5359c22..1a3bb98 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -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 \



reply via email to

[Prev in Thread] Current Thread [Next in Thread]