From 7465b002f9c8850a279568f832ff238ad5ba1476 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 19 Jul 2007 10:14:41 +0200 Subject: "cp -i --update older newer" no longer prompts; same for mv * src/copy.c (copy_internal): Perform "update" check before the possible interactive prompt. Reported by zeno_AT_biyg_DOT_org in * tests/mv/update: Add tests for the above. * NEWS: Mention the bug fix. --- src/copy.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/copy.c b/src/copy.c index b7bf73b83..0e549d253 100644 --- a/src/copy.c +++ b/src/copy.c @@ -1210,6 +1210,30 @@ copy_internal (char const *src_name, char const *dst_name, return false; } + if (!S_ISDIR (src_mode) && x->update) + { + /* When preserving time stamps (but not moving within a file + system), don't worry if the destination time stamp is + less than the source merely because of time stamp + truncation. */ + int options = ((x->preserve_timestamps + && ! (x->move_mode + && dst_sb.st_dev == src_sb.st_dev)) + ? UTIMECMP_TRUNCATE_SOURCE + : 0); + + if (0 <= utimecmp (dst_name, &dst_sb, &src_sb, options)) + { + /* We're using --update and the destination is not older + than the source, so do not copy or move. Pretend the + rename succeeded, so the caller (if it's mv) doesn't + end up removing the source file. */ + if (rename_succeeded) + *rename_succeeded = true; + return true; + } + } + /* When there is an existing destination file, we may end up returning early, and hence not copying/moving the file. This may be due to an interactive `negative' reply to the @@ -1302,30 +1326,6 @@ copy_internal (char const *src_name, char const *dst_name, return false; } } - - if (x->update) - { - /* When preserving time stamps (but not moving within a file - system), don't worry if the destination time stamp is - less than the source merely because of time stamp - truncation. */ - int options = ((x->preserve_timestamps - && ! (x->move_mode - && dst_sb.st_dev == src_sb.st_dev)) - ? UTIMECMP_TRUNCATE_SOURCE - : 0); - - if (0 <= utimecmp (dst_name, &dst_sb, &src_sb, options)) - { - /* We're using --update and the destination is not older - than the source, so do not copy or move. Pretend the - rename succeeded, so the caller (if it's mv) doesn't - end up removing the source file. */ - if (rename_succeeded) - *rename_succeeded = true; - return true; - } - } } if (x->move_mode) -- cgit v1.2.3-70-g09d2