]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: simplify handling of backup --suffix in various tools
authorRishabh Dave <rishabhddave@gmail.com>
Wed, 2 Nov 2016 23:43:47 +0000 (23:43 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 7 Nov 2016 17:09:35 +0000 (17:09 +0000)
* src/cp.c (main): Avoid the getenv("SIMPLE_BACKUP_SUFFIX") call,
which is now done if needed in the gnulib backupfile module.
Also avoid the redundant strdup, as we don't modify this suffix.
* src/install.c (main): Likewise.
* src/ln.c (main): Likewise.
* src/mv.c (main): Likewise.
Fixes http://bugs.gnu.org/23153

src/cp.c
src/install.c
src/ln.c
src/mv.c

index b25c9ce72fcac13acc1544dc68a787a80275a630..79b93bd8e8970e14e890e67134722cba70c0da18 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
@@ -922,7 +922,6 @@ main (int argc, char **argv)
   int c;
   bool ok;
   bool make_backups = false;
-  char *backup_suffix_string;
   char *version_control_string = NULL;
   struct cp_options x;
   bool copy_contents = false;
@@ -941,10 +940,6 @@ main (int argc, char **argv)
   selinux_enabled = (0 < is_selinux_enabled ());
   cp_option_init (&x);
 
-  /* FIXME: consider not calling getenv for SIMPLE_BACKUP_SUFFIX unless
-     we'll actually use backup_suffix_string.  */
-  backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
-
   while ((c = getopt_long (argc, argv, "abdfHilLnprst:uvxPRS:TZ",
                            long_opts, NULL))
          != -1)
@@ -1123,7 +1118,7 @@ main (int argc, char **argv)
 
         case 'S':
           make_backups = true;
-          backup_suffix_string = optarg;
+          simple_backup_suffix = optarg;
           break;
 
         case_GETOPT_HELP_CHAR;
@@ -1154,9 +1149,6 @@ main (int argc, char **argv)
       usage (EXIT_FAILURE);
     }
 
-  if (backup_suffix_string)
-    simple_backup_suffix = xstrdup (backup_suffix_string);
-
   x.backup_type = (make_backups
                    ? xget_version (_("backup type"),
                                    version_control_string)
index 9182e50f7d53dab70f02eb7c34f3075e546b30b8..b4b282aae02d3bec870377ae04ab09edd0284b20 100644 (file)
@@ -807,7 +807,6 @@ main (int argc, char **argv)
   int exit_status = EXIT_SUCCESS;
   const char *specified_mode = NULL;
   bool make_backups = false;
-  char *backup_suffix_string;
   char *version_control_string = NULL;
   bool mkdir_and_install = false;
   struct cp_options x;
@@ -836,10 +835,6 @@ main (int argc, char **argv)
   dir_arg = false;
   umask (0);
 
-  /* FIXME: consider not calling getenv for SIMPLE_BACKUP_SUFFIX unless
-     we'll actually use backup_suffix_string.  */
-  backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
-
   while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pt:TvS:Z", long_options,
                               NULL)) != -1)
     {
@@ -889,7 +884,7 @@ main (int argc, char **argv)
           break;
         case 'S':
           make_backups = true;
-          backup_suffix_string = optarg;
+          simple_backup_suffix = optarg;
           break;
         case 't':
           if (target_directory)
@@ -961,9 +956,6 @@ main (int argc, char **argv)
              quoteaf (target_directory));
     }
 
-  if (backup_suffix_string)
-    simple_backup_suffix = xstrdup (backup_suffix_string);
-
   x.backup_type = (make_backups
                    ? xget_version (_("backup type"),
                                    version_control_string)
index 618b03dcceb0d4aa61395c26cc96249c48665ff9..0b8eb219b12e9b4fc95d5897481ed3ef6bf96f2d 100644 (file)
--- a/src/ln.c
+++ b/src/ln.c
@@ -465,7 +465,6 @@ main (int argc, char **argv)
   int c;
   bool ok;
   bool make_backups = false;
-  char *backup_suffix_string;
   char *version_control_string = NULL;
   char const *target_directory = NULL;
   bool no_target_directory = false;
@@ -480,10 +479,6 @@ main (int argc, char **argv)
 
   atexit (close_stdin);
 
-  /* FIXME: consider not calling getenv for SIMPLE_BACKUP_SUFFIX unless
-     we'll actually use backup_suffix_string.  */
-  backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
-
   symbolic_link = remove_existing_files = interactive = verbose
     = hard_dir_link = false;
 
@@ -547,7 +542,7 @@ main (int argc, char **argv)
           break;
         case 'S':
           make_backups = true;
-          backup_suffix_string = optarg;
+          simple_backup_suffix = optarg;
           break;
         case_GETOPT_HELP_CHAR;
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -594,9 +589,6 @@ main (int argc, char **argv)
              quoteaf (file[n_files - 1]));
     }
 
-  if (backup_suffix_string)
-    simple_backup_suffix = xstrdup (backup_suffix_string);
-
   backup_type = (make_backups
                  ? xget_version (_("backup type"), version_control_string)
                  : no_backups);
index 25fa8a4f14b64b52c0efc08f5b4172c34f85f8a4..35b2e929fc21aa4b5bde991cec3b867247033c80 100644 (file)
--- a/src/mv.c
+++ b/src/mv.c
@@ -347,7 +347,6 @@ main (int argc, char **argv)
   int c;
   bool ok;
   bool make_backups = false;
-  char *backup_suffix_string;
   char *version_control_string = NULL;
   struct cp_options x;
   char *target_directory = NULL;
@@ -369,10 +368,6 @@ main (int argc, char **argv)
   /* Try to disable the ability to unlink a directory.  */
   priv_set_remove_linkdir ();
 
-  /* FIXME: consider not calling getenv for SIMPLE_BACKUP_SUFFIX unless
-     we'll actually use backup_suffix_string.  */
-  backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
-
   while ((c = getopt_long (argc, argv, "bfint:uvS:TZ", long_options, NULL))
          != -1)
     {
@@ -421,7 +416,7 @@ main (int argc, char **argv)
           break;
         case 'S':
           make_backups = true;
-          backup_suffix_string = optarg;
+          simple_backup_suffix = optarg;
           break;
         case 'Z':
           /* As a performance enhancement, don't even bother trying
@@ -481,9 +476,6 @@ main (int argc, char **argv)
       usage (EXIT_FAILURE);
     }
 
-  if (backup_suffix_string)
-    simple_backup_suffix = xstrdup (backup_suffix_string);
-
   x.backup_type = (make_backups
                    ? xget_version (_("backup type"),
                                    version_control_string)