diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-13 16:52:00 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-13 16:52:00 +0000 |
| commit | d5fe880a57bc140f2e1469d2f1c75f815df94eff (patch) | |
| tree | 666b3f300bf6eebfd407df9b6d4a0192275eeb8e | |
| parent | 9d96af2e83a9519ac89ff0f8dae7f8478d33f581 (diff) | |
| download | busybox-w32-d5fe880a57bc140f2e1469d2f1c75f815df94eff.tar.gz busybox-w32-d5fe880a57bc140f2e1469d2f1c75f815df94eff.tar.bz2 busybox-w32-d5fe880a57bc140f2e1469d2f1c75f815df94eff.zip | |
cp: add ENABLE_FEATURE_VERBOSE_CP_MESSAGE. Closes bug 1470
| -rw-r--r-- | coreutils/libcoreutils/cp_mv_stat.c | 6 | ||||
| -rw-r--r-- | libbb/Config.in | 15 | ||||
| -rw-r--r-- | libbb/copy_file.c | 12 |
3 files changed, 32 insertions, 1 deletions
diff --git a/coreutils/libcoreutils/cp_mv_stat.c b/coreutils/libcoreutils/cp_mv_stat.c index 43583d48b..ff7c27399 100644 --- a/coreutils/libcoreutils/cp_mv_stat.c +++ b/coreutils/libcoreutils/cp_mv_stat.c | |||
| @@ -27,6 +27,12 @@ int cp_mv_stat2(const char *fn, struct stat *fn_stat, stat_func sf) | |||
| 27 | { | 27 | { |
| 28 | if (sf(fn, fn_stat) < 0) { | 28 | if (sf(fn, fn_stat) < 0) { |
| 29 | if (errno != ENOENT) { | 29 | if (errno != ENOENT) { |
| 30 | #if ENABLE_FEATURE_VERBOSE_CP_MESSAGE | ||
| 31 | if (errno == ENOTDIR) { | ||
| 32 | bb_error_msg("cannot stat '%s': Path has non-directory component", fn); | ||
| 33 | return -1; | ||
| 34 | } | ||
| 35 | #endif | ||
| 30 | bb_perror_msg("cannot stat '%s'", fn); | 36 | bb_perror_msg("cannot stat '%s'", fn); |
| 31 | return -1; | 37 | return -1; |
| 32 | } | 38 | } |
diff --git a/libbb/Config.in b/libbb/Config.in index 0ad4381d9..9389fe808 100644 --- a/libbb/Config.in +++ b/libbb/Config.in | |||
| @@ -102,6 +102,21 @@ config FEATURE_EDITING_FANCY_PROMPT | |||
| 102 | Setting this option allows for prompts to use things like \w and | 102 | Setting this option allows for prompts to use things like \w and |
| 103 | \$ and escape codes. | 103 | \$ and escape codes. |
| 104 | 104 | ||
| 105 | config FEATURE_VERBOSE_CP_MESSAGE | ||
| 106 | bool "Give more precise messages when copy fails (cp, mv etc)" | ||
| 107 | default n | ||
| 108 | help | ||
| 109 | Error messages with this feature enabled: | ||
| 110 | $ cp file /does_not_exist/file | ||
| 111 | cp: cannot create '/does_not_exist/file': Path does not exist | ||
| 112 | $ cp file /vmlinuz/file | ||
| 113 | cp: cannot stat '/vmlinuz/file': Path has non-directory component | ||
| 114 | If this feature is not enabled, they will be, respectively: | ||
| 115 | cp: cannot remove '/does_not_exist/file': No such file or directory | ||
| 116 | cp: cannot stat '/vmlinuz/file': Not a directory | ||
| 117 | respectively. | ||
| 118 | This will cost you ~60 bytes. | ||
| 119 | |||
| 105 | config FEATURE_COPYBUF_KB | 120 | config FEATURE_COPYBUF_KB |
| 106 | int "Copy buffer size, in kilobytes" | 121 | int "Copy buffer size, in kilobytes" |
| 107 | range 1 1024 | 122 | range 1 1024 |
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index 3da8a3531..d37d51562 100644 --- a/libbb/copy_file.c +++ b/libbb/copy_file.c | |||
| @@ -29,6 +29,7 @@ | |||
| 29 | // for POSIX mode to give reasonable error message | 29 | // for POSIX mode to give reasonable error message |
| 30 | static int ask_and_unlink(const char *dest, int flags) | 30 | static int ask_and_unlink(const char *dest, int flags) |
| 31 | { | 31 | { |
| 32 | int e = errno; | ||
| 32 | #if DO_POSIX_CP | 33 | #if DO_POSIX_CP |
| 33 | if (!(flags & (FILEUTILS_FORCE|FILEUTILS_INTERACTIVE))) { | 34 | if (!(flags & (FILEUTILS_FORCE|FILEUTILS_INTERACTIVE))) { |
| 34 | // Either it exists, or the *path* doesnt exist | 35 | // Either it exists, or the *path* doesnt exist |
| @@ -50,7 +51,16 @@ static int ask_and_unlink(const char *dest, int flags) | |||
| 50 | return 0; // not allowed to overwrite | 51 | return 0; // not allowed to overwrite |
| 51 | } | 52 | } |
| 52 | if (unlink(dest) < 0) { | 53 | if (unlink(dest) < 0) { |
| 53 | bb_perror_msg("cannot remove '%s'", dest); | 54 | #if ENABLE_FEATURE_VERBOSE_CP_MESSAGE |
| 55 | if (e == errno && e == ENOENT) { | ||
| 56 | /* e == ENOTDIR is similar: path has non-dir component, | ||
| 57 | * but in this case we don't even reach copy_file() */ | ||
| 58 | bb_error_msg("cannot create '%s': Path does not exist", dest); | ||
| 59 | return -1; // error | ||
| 60 | } | ||
| 61 | #endif | ||
| 62 | errno = e; | ||
| 63 | bb_perror_msg("cannot create '%s'", dest); | ||
| 54 | return -1; // error | 64 | return -1; // error |
| 55 | } | 65 | } |
| 56 | return 1; // ok (to try again) | 66 | return 1; // ok (to try again) |
