Hi,

I have added functional verbose switch to a few Coreutils commands. As the bug #7046 submitter, I find it useful for logging and scripting purposes. If you are interested, I can do the rest of commands since the ignored switch is already in the code for compatibility reasons.

Signed-off-by: Igor Živković <[email protected]>
diff --git a/coreutils/cp.c b/coreutils/cp.c
index de2e512..d4ec626 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -31,6 +31,7 @@
 //usage:     "\n       -f      Overwrite"
 //usage:     "\n       -i      Prompt before overwrite"
 //usage:     "\n       -l,-s   Create (sym)links"
+//usage:     "\n       -v      Verbose"
 
 #include "libbb.h"
 #include "libcoreutils/coreutils.h"
@@ -79,7 +80,6 @@
                "parents\0"        No_argument "\xff"
                ;
 #endif
-       // -v (--verbose) is ignored
        flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
        /* Options of cp from GNU coreutils 6.10:
         * -a, --archive
@@ -194,6 +194,10 @@
  DO_COPY:
                if (copy_file(*argv, dest, flags) < 0) {
                        status = EXIT_FAILURE;
+               } else {
+                       if (flags & OPT_v) {
+                               printf("'%s' -> '%s'\n", *argv, dest);
+                       }
                }
                if (*++argv == last) {
                        /* possibly leaking dest... */
diff --git a/coreutils/mv.c b/coreutils/mv.c
index f127dfa..444b84c 100644
--- a/coreutils/mv.c
+++ b/coreutils/mv.c
@@ -17,13 +17,14 @@
 #include "libcoreutils/coreutils.h"
 
 //usage:#define mv_trivial_usage
-//usage:       "[-fin] SOURCE DEST\n"
-//usage:       "or: mv [-fin] SOURCE... DIRECTORY"
+//usage:       "[-finv] SOURCE DEST\n"
+//usage:       "or: mv [-finv] SOURCE... DIRECTORY"
 //usage:#define mv_full_usage "\n\n"
 //usage:       "Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY\n"
 //usage:     "\n       -f      Don't prompt before overwriting"
 //usage:     "\n       -i      Interactive, prompt before overwrite"
 //usage:     "\n       -n      Don't overwrite an existing file"
+//usage:     "\n       -v      Verbose"
 //usage:
 //usage:#define mv_example_usage
 //usage:       "$ mv /tmp/foo /bin/bar\n"
@@ -40,6 +41,7 @@
 #define OPT_FORCE       (1 << 0)
 #define OPT_INTERACTIVE (1 << 1)
 #define OPT_NOCLOBBER   (1 << 2)
+#define OPT_VERBOSE     (1 << 3)
 
 int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int mv_main(int argc, char **argv)
@@ -58,7 +60,6 @@
        /* Need at least two arguments.
         * If more than one of -f, -i, -n is specified , only the final one
         * takes effect (it unsets previous options).
-        * -v is accepted but ignored.
         */
        opt_complementary = "-2:f-in:i-fn:n-fi";
        flags = getopt32(argv, "finv");
@@ -148,6 +149,9 @@
                        status = 1;
                }
  RET_0:
+               if (flags & OPT_VERBOSE) {
+                       printf("'%s' -> '%s'\n", *argv, dest);
+               }
                if (dest != last) {
                        free((void *) dest);
                }
diff --git a/coreutils/rm.c b/coreutils/rm.c
index 042fba1..5cef5d9 100644
--- a/coreutils/rm.c
+++ b/coreutils/rm.c
@@ -22,6 +22,7 @@
 //usage:     "\n       -i      Always prompt before removing"
 //usage:     "\n       -f      Never prompt"
 //usage:     "\n       -R,-r   Recurse"
+//usage:     "\n       -v      Verbose"
 //usage:
 //usage:#define rm_example_usage
 //usage:       "$ rm -rf /tmp/foo\n"
@@ -38,7 +39,6 @@
        unsigned opt;
 
        opt_complementary = "f-i:i-f";
-       /* -v (verbose) is ignored */
        opt = getopt32(argv, "fiRrv");
        argv += optind;
        if (opt & 1)
@@ -47,6 +47,8 @@
                flags |= FILEUTILS_INTERACTIVE;
        if (opt & (8|4))
                flags |= FILEUTILS_RECUR;
+       if (opt & 16)
+               flags |= FILEUTILS_VERBOSE;
 
        if (*argv != NULL) {
                do {
@@ -55,6 +57,9 @@
                        if (DOT_OR_DOTDOT(base)) {
                                bb_error_msg("can't remove '.' or '..'");
                        } else if (remove_file(*argv, flags) >= 0) {
+                               if (flags & FILEUTILS_VERBOSE) {
+                                       printf("removed '%s'\n", *argv);
+                               }
                                continue;
                        }
                        status = 1;
diff --git a/include/libbb.h b/include/libbb.h
index 1cbe2c8..e90c126 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -334,6 +334,7 @@
        FILEUTILS_SET_SECURITY_CONTEXT = 1 << 10,
 #endif
        FILEUTILS_IGNORE_CHMOD_ERR = 1 << 11,
+       FILEUTILS_VERBOSE         = 1 << 12, /* -v */
 };
 #define FILEUTILS_CP_OPTSTR "pdRfilsLH" IF_SELINUX("c")
 extern int remove_file(const char *path, int flags) FAST_FUNC;
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to