svn commit: trunk/busybox: coreutils/libcoreutils libbb

vda at busybox.net vda at busybox.net
Wed Feb 13 16:52:01 UTC 2008


Author: vda
Date: 2008-02-13 08:52:00 -0800 (Wed, 13 Feb 2008)
New Revision: 21006

Log:
cp: add ENABLE_FEATURE_VERBOSE_CP_MESSAGE. Closes bug 1470



Modified:
   trunk/busybox/coreutils/libcoreutils/cp_mv_stat.c
   trunk/busybox/libbb/Config.in
   trunk/busybox/libbb/copy_file.c


Changeset:
Modified: trunk/busybox/coreutils/libcoreutils/cp_mv_stat.c
===================================================================
--- trunk/busybox/coreutils/libcoreutils/cp_mv_stat.c	2008-02-13 15:35:52 UTC (rev 21005)
+++ trunk/busybox/coreutils/libcoreutils/cp_mv_stat.c	2008-02-13 16:52:00 UTC (rev 21006)
@@ -27,6 +27,12 @@
 {
 	if (sf(fn, fn_stat) < 0) {
 		if (errno != ENOENT) {
+#if ENABLE_FEATURE_VERBOSE_CP_MESSAGE
+			if (errno == ENOTDIR) {
+				bb_error_msg("cannot stat '%s': Path has non-directory component", fn);
+				return -1;
+			}
+#endif
 			bb_perror_msg("cannot stat '%s'", fn);
 			return -1;
 		}

Modified: trunk/busybox/libbb/Config.in
===================================================================
--- trunk/busybox/libbb/Config.in	2008-02-13 15:35:52 UTC (rev 21005)
+++ trunk/busybox/libbb/Config.in	2008-02-13 16:52:00 UTC (rev 21006)
@@ -102,6 +102,21 @@
 	  Setting this option allows for prompts to use things like \w and
 	  \$ and escape codes.
 
+config FEATURE_VERBOSE_CP_MESSAGE
+	bool "Give more precise messages when copy fails (cp, mv etc)"
+	default n
+	help
+	  Error messages with this feature enabled:
+	    $ cp file /does_not_exist/file
+	    cp: cannot create '/does_not_exist/file': Path does not exist
+	    $ cp file /vmlinuz/file
+	    cp: cannot stat '/vmlinuz/file': Path has non-directory component
+	  If this feature is not enabled, they will be, respectively:
+	    cp: cannot remove '/does_not_exist/file': No such file or directory
+	    cp: cannot stat '/vmlinuz/file': Not a directory
+	  respectively.
+	  This will cost you ~60 bytes.
+
 config FEATURE_COPYBUF_KB
 	int "Copy buffer size, in kilobytes"
 	range 1 1024

Modified: trunk/busybox/libbb/copy_file.c
===================================================================
--- trunk/busybox/libbb/copy_file.c	2008-02-13 15:35:52 UTC (rev 21005)
+++ trunk/busybox/libbb/copy_file.c	2008-02-13 16:52:00 UTC (rev 21006)
@@ -29,6 +29,7 @@
 // for POSIX mode to give reasonable error message
 static int ask_and_unlink(const char *dest, int flags)
 {
+	int e = errno;
 #if DO_POSIX_CP
 	if (!(flags & (FILEUTILS_FORCE|FILEUTILS_INTERACTIVE))) {
 		// Either it exists, or the *path* doesnt exist
@@ -50,7 +51,16 @@
 			return 0; // not allowed to overwrite
 	}
 	if (unlink(dest) < 0) {
-		bb_perror_msg("cannot remove '%s'", dest);
+#if ENABLE_FEATURE_VERBOSE_CP_MESSAGE
+		if (e == errno && e == ENOENT) {
+			/* e == ENOTDIR is similar: path has non-dir component,
+			 * but in this case we don't even reach copy_file() */
+			bb_error_msg("cannot create '%s': Path does not exist", dest);
+			return -1; // error
+		}
+#endif
+		errno = e;
+		bb_perror_msg("cannot create '%s'", dest);
 		return -1; // error
 	}
 	return 1; // ok (to try again)




More information about the busybox-cvs mailing list