aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-08-24 14:23:57 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-08-24 14:23:57 +0000
commit3d829627fb5e6631a106fd5f03824426c06eab42 (patch)
treefd3fc8a6830f138b678b9d569d53c4e0a3667bf3 /libbb
parentcab774d6e5c41c110345e5ce95d78ff714e2ece7 (diff)
downloadbusybox-w32-3d829627fb5e6631a106fd5f03824426c06eab42.tar.gz
busybox-w32-3d829627fb5e6631a106fd5f03824426c06eab42.tar.bz2
busybox-w32-3d829627fb5e6631a106fd5f03824426c06eab42.zip
cp: make POSIX-me-harder mode complain with a bit less insane message
Diffstat (limited to 'libbb')
-rw-r--r--libbb/copy_file.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index b68a257b5..8a7db77e6 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -22,25 +22,25 @@
22 22
23#define DO_POSIX_CP 0 /* 1 - POSIX behavior, 0 - safe behavior */ 23#define DO_POSIX_CP 0 /* 1 - POSIX behavior, 0 - safe behavior */
24 24
25 25// errno must be set to relevant value ("why we cannot create dest?")
26// for POSIX mode to give reasonable error message
26static int ask_and_unlink(const char *dest, int flags) 27static int ask_and_unlink(const char *dest, int flags)
27{ 28{
28 // If !DO_POSIX_CP, act as if -f is always in effect - we don't want
29 // "'file' exists" msg, we want unlink to be done (silently unless -i
30 // is also in effect).
31 // This prevents safe way from asking more questions than POSIX does.
32#if DO_POSIX_CP 29#if DO_POSIX_CP
33 if (!(flags & (FILEUTILS_FORCE|FILEUTILS_INTERACTIVE))) { 30 if (!(flags & (FILEUTILS_FORCE|FILEUTILS_INTERACTIVE))) {
34 fprintf(stderr, "'%s' exists\n", dest); 31 // Either it exists, or the *path* doesnt exist
32 bb_perror_msg("cannot create '%s'", dest);
35 return -1; 33 return -1;
36 } 34 }
37#endif 35#endif
36 // If !DO_POSIX_CP, act as if -f is always in effect - we don't want
37 // "cannot create" msg, we want unlink to be done (silently unless -i).
38 38
39 // TODO: maybe we should do it only if ctty is present? 39 // TODO: maybe we should do it only if ctty is present?
40 if (flags & FILEUTILS_INTERACTIVE) { 40 if (flags & FILEUTILS_INTERACTIVE) {
41 // We would not do POSIX insanity. -i asks, 41 // We would not do POSIX insanity. -i asks,
42 // then _unlinks_ the offender. Presto. 42 // then _unlinks_ the offender. Presto.
43 // (No opening without O_EXCL, no unlinks only if -f) 43 // (No "opening without O_EXCL", no "unlink only if -f")
44 // Or else we will end up having 3 open()s! 44 // Or else we will end up having 3 open()s!
45 fprintf(stderr, "%s: overwrite '%s'? ", applet_name, dest); 45 fprintf(stderr, "%s: overwrite '%s'? ", applet_name, dest);
46 if (!bb_ask_confirmation()) 46 if (!bb_ask_confirmation())
@@ -280,6 +280,7 @@ int copy_file(const char *source, const char *dest, int flags)
280 ) { 280 ) {
281 // We are lazy here, a bit lax with races... 281 // We are lazy here, a bit lax with races...
282 if (dest_exists) { 282 if (dest_exists) {
283 errno = EEXIST;
283 ovr = ask_and_unlink(dest, flags); 284 ovr = ask_and_unlink(dest, flags);
284 if (ovr <= 0) 285 if (ovr <= 0)
285 return ovr; 286 return ovr;