Hello,
I have wrote the attached patch for following FIXME in file src/cp.c -
/* FIXME: consider not calling getenv for SIMPLE_BACKUP_SUFFIX unless
we'll actually use backup_suffix_string. */
backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
Since we use backup_suffix_string to duplicate it into
simple_backup_suffix, I brought the getenv() call there, that too, only if
required (as simple_backup_suffix already stores tilde already).
I did 'diff -ur' directly against original cp.c (named cp-original.c,
then) to create the patch. I tested patch using -b, --backup and --suffix
option of c. Version I have used is latest one on savannah.gnu.org -
coreuitls-8.25.
There was cppi (didn't know what it does) at the bottom of coreutil's
download page. After reading it's README, I concluded that it is not to be
considered while debugging/fixing coreutils. Hopefully, I was correct in
doing so.
If incorrect, please do correct me in any case. :)
There was one little doubt, maybe bug, after doing '--backups=numbered' it
becomes impossible to have suffixed backups (using --suffix or -b) until we
do '--backup=simple' explicitly. Is this supposed to be? I tried with both
altered and unaltered version of cp.
(And should I have or should create/d a new separate thread? I wasn't sure.)
--- cp-original.c 2016-01-01 19:18:50.000000000 +0530
+++ cp-edited.c 2016-03-29 20:13:47.274362100 +0530
@@ -920,7 +920,7 @@
int c;
bool ok;
bool make_backups = false;
- char *backup_suffix_string;
+ char *backup_suffix_string = NULL;
char *version_control_string = NULL;
struct cp_options x;
bool copy_contents = false;
@@ -939,10 +939,6 @@
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)
@@ -1151,6 +1147,11 @@
usage (EXIT_FAILURE);
}
+ /* If backup_suffix_string is still null (i.e. no --suffix or --backup =
+ numbered | existing), try to get it from environment. */
+ if (!backup_suffix_string)
+ backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
+
if (backup_suffix_string)
simple_backup_suffix = xstrdup (backup_suffix_string);