Tizen 2.0 Release
[external/tizen-coreutils.git] / packaging / coreutils-6.9-cp-i-u.patch
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.
5
6 The following patch eliminates the unnecessary prompt in that case.
7
8 diff --git a/src/copy.c b/src/copy.c
9 index b7bf73b..0e549d2 100644
10 --- a/src/copy.c
11 +++ b/src/copy.c
12 @@ -1210,6 +1210,30 @@ copy_internal (char const *src_name, char const *dst_name,
13               return false;
14             }
15
16 +         if (!S_ISDIR (src_mode) && x->update)
17 +           {
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
21 +                truncation.  */
22 +             int options = ((x->preserve_timestamps
23 +                             && ! (x->move_mode
24 +                                   && dst_sb.st_dev == src_sb.st_dev))
25 +                            ? UTIMECMP_TRUNCATE_SOURCE
26 +                            : 0);
27 +
28 +             if (0 <= utimecmp (dst_name, &dst_sb, &src_sb, options))
29 +               {
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;
36 +                 return true;
37 +               }
38 +           }
39 +
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,
44                       return false;
45                     }
46                 }
47 -
48 -             if (x->update)
49 -               {
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
53 -                    truncation.  */
54 -                 int options = ((x->preserve_timestamps
55 -                                 && ! (x->move_mode
56 -                                       && dst_sb.st_dev == src_sb.st_dev))
57 -                                ? UTIMECMP_TRUNCATE_SOURCE
58 -                                : 0);
59 -
60 -                 if (0 <= utimecmp (dst_name, &dst_sb, &src_sb, options))
61 -                   {
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;
68 -                     return true;
69 -                   }
70 -               }
71             }
72
73           if (x->move_mode)
74 diff --git a/tests/mv/update b/tests/mv/update
75 index 0c06024..6c3d149 100755
76 --- a/tests/mv/update
77 +++ b/tests/mv/update
78 @@ -1,7 +1,7 @@
79  #!/bin/sh
80  # make sure --update works as advertised
81
82 -# Copyright (C) 2001, 2004, 2006 Free Software Foundation, Inc.
83 +# Copyright (C) 2001, 2004, 2006-2007 Free Software Foundation, Inc.
84
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
88
89  fail=0
90
91 -for cp_or_mv in cp mv; do
92 -  # This is a no-op.
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
105 +  done
106  done
107
108  # This will actually perform the rename.
109 --
110 1.5.3.rc1.16.g9d6f