1 When "cp -i --update old new" would do nothing because "new" is
2 newer than "old", cp would nonetheless prompt for whether it is
3 ok to overwrite "new". Then, regardless of the response (because
4 of the --update option), cp would do nothing.
6 The following patch eliminates the unnecessary prompt in that case.
8 diff --git a/src/copy.c b/src/copy.c
9 index b7bf73b..0e549d2 100644
12 @@ -1210,6 +1210,30 @@ copy_internal (char const *src_name, char const *dst_name,
16 + if (!S_ISDIR (src_mode) && x->update)
18 + /* When preserving time stamps (but not moving within a file
19 + system), don't worry if the destination time stamp is
20 + less than the source merely because of time stamp
22 + int options = ((x->preserve_timestamps
24 + && dst_sb.st_dev == src_sb.st_dev))
25 + ? UTIMECMP_TRUNCATE_SOURCE
28 + if (0 <= utimecmp (dst_name, &dst_sb, &src_sb, options))
30 + /* We're using --update and the destination is not older
31 + than the source, so do not copy or move. Pretend the
32 + rename succeeded, so the caller (if it's mv) doesn't
33 + end up removing the source file. */
34 + if (rename_succeeded)
35 + *rename_succeeded = true;
40 /* When there is an existing destination file, we may end up
41 returning early, and hence not copying/moving the file.
42 This may be due to an interactive `negative' reply to the
43 @@ -1302,30 +1326,6 @@ copy_internal (char const *src_name, char const *dst_name,
50 - /* When preserving time stamps (but not moving within a file
51 - system), don't worry if the destination time stamp is
52 - less than the source merely because of time stamp
54 - int options = ((x->preserve_timestamps
56 - && dst_sb.st_dev == src_sb.st_dev))
57 - ? UTIMECMP_TRUNCATE_SOURCE
60 - if (0 <= utimecmp (dst_name, &dst_sb, &src_sb, options))
62 - /* We're using --update and the destination is not older
63 - than the source, so do not copy or move. Pretend the
64 - rename succeeded, so the caller (if it's mv) doesn't
65 - end up removing the source file. */
66 - if (rename_succeeded)
67 - *rename_succeeded = true;
74 diff --git a/tests/mv/update b/tests/mv/update
75 index 0c06024..6c3d149 100755
80 # make sure --update works as advertised
82 -# Copyright (C) 2001, 2004, 2006 Free Software Foundation, Inc.
83 +# Copyright (C) 2001, 2004, 2006-2007 Free Software Foundation, Inc.
85 # This program is free software; you can redistribute it and/or modify
86 # it under the terms of the GNU General Public License as published by
87 @@ -46,11 +46,16 @@ fi
91 -for cp_or_mv in cp mv; do
93 - $cp_or_mv --update old new || fail=1
94 - case "`cat new`" in new) ;; *) fail=1 ;; esac
95 - case "`cat old`" in old) ;; *) fail=1 ;; esac
96 +for interactive in '' -i; do
97 + for cp_or_mv in cp mv; do
98 + # This is a no-op, with no prompt.
99 + # With coreutils-6.9 and earlier, using --update with -i would
100 + # mistakenly elicit a prompt.
101 + $cp_or_mv $interactive --update old new < /dev/null > out 2>&1 || fail=1
102 + test -s out && fail=1
103 + case "`cat new`" in new) ;; *) fail=1 ;; esac
104 + case "`cat old`" in old) ;; *) fail=1 ;; esac
108 # This will actually perform the rename.