>From 7e244891b0c41bbf9f5b5917d1a71c183a8367ac Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 4 Jan 2018 13:57:40 -0800 Subject: [PATCH 1/2] mv: -n overrides -u * NEWS: Mention these fixes. * doc/coreutils.texi (cp invocation, mv invocation): Mention that -n is silent, and that it overrides -u. * src/cp.c, src/mv.c (main): -n overrides -u. --- NEWS | 7 +++++++ doc/coreutils.texi | 13 +++++++++---- src/cp.c | 3 +++ src/mv.c | 3 +++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index b89254f7e..4712f5a46 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,13 @@ GNU coreutils NEWS -*- outline -*- * Noteworthy changes in release ?.? (????-??-??) [?] +** Bug fixes + + 'cp -n -u' and 'mv -n -u' now consistently ignore the -u option. + Previously, this option combination suffered from race conditions + that caused -u to sometimes override -n. + [bug introduced with coreutils-7.1] + * Noteworthy changes in release 8.29 (2017-12-27) [stable] diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 1c0e8a36c..6bb9f0906 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -8569,7 +8569,8 @@ a regular file in the destination tree. @itemx --no-clobber @opindex -n @opindex --no-clobber -Do not overwrite an existing file. The @option{-n} option overrides a previous +Do not overwrite an existing file; silently do nothing instead. +This option overrides a previous @option{-i} option. This option is mutually exclusive with @option{-b} or @option{--backup} option. @@ -8809,8 +8810,10 @@ the comparison is to the source timestamp truncated to the resolutions of the destination file system and of the system calls used to update timestamps; this avoids duplicate work if several @samp{cp -pu} commands are executed with the same source and destination. -If @option{--preserve=links} is also specified (like with @samp{cp -au} -for example), that will take precedence. Consequently, depending on the +This option is ignored if the @option{-n} or @option{--no-clobber} +option is also specified. +Also, if @option{--preserve=links} is also specified (like with @samp{cp -au} +for example), that will take precedence; consequently, depending on the order that files are processed from the source, newer files in the destination may be replaced, to mirror hard links in the source. @@ -9657,7 +9660,7 @@ If the response is not affirmative, the file is skipped. @opindex -n @opindex --no-clobber @cindex prompts, omitting -Do not overwrite an existing file. +Do not overwrite an existing file; silently do nothing instead. @mvOptsIfn This option is mutually exclusive with @option{-b} or @option{--backup} option. @@ -9673,6 +9676,8 @@ source timestamp truncated to the resolutions of the destination file system and of the system calls used to update timestamps; this avoids duplicate work if several @samp{mv -u} commands are executed with the same source and destination. +This option is ignored if the @option{-n} or @option{--no-clobber} +option is also specified. @item -v @itemx --verbose diff --git a/src/cp.c b/src/cp.c index 1b5bf7285..d81d41859 100644 --- a/src/cp.c +++ b/src/cp.c @@ -1145,6 +1145,9 @@ main (int argc, char **argv) usage (EXIT_FAILURE); } + if (x.interactive == I_ALWAYS_NO) + x.update = false; + if (make_backups && x.interactive == I_ALWAYS_NO) { error (0, 0, diff --git a/src/mv.c b/src/mv.c index a8df730a7..818ca59b6 100644 --- a/src/mv.c +++ b/src/mv.c @@ -459,6 +459,9 @@ main (int argc, char **argv) quoteaf (file[n_files - 1])); } + if (x.interactive == I_ALWAYS_NO) + x.update = false; + if (make_backups && x.interactive == I_ALWAYS_NO) { error (0, 0, -- 2.14.3