Hi,

if anyone is interested, I have updated my previous coreutils-like verbose switch patch to include mkdir and rmdir, and to fix recursive messages for cp and rm commands.

Regards,
Signed-off-by: Igor Živković <[email protected]>

diff --git a/coreutils/cp.c b/coreutils/cp.c
index de2e512..c8f943a 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
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c
index 4a8e43e..806899e 100644
--- a/coreutils/mkdir.c
+++ b/coreutils/mkdir.c
@@ -25,6 +25,7 @@
 //usage:       "Create DIRECTORY\n"
 //usage:     "\n       -m MODE Mode"
 //usage:     "\n       -p      No error if exists; make parent directories as 
needed"
+//usage:     "\n       -v      Verbose"
 //usage:       IF_SELINUX(
 //usage:     "\n       -Z      Set security context"
 //usage:       )
@@ -45,10 +46,10 @@
 static const char mkdir_longopts[] ALIGN1 =
        "mode\0"    Required_argument "m"
        "parents\0" No_argument       "p"
+       "verbose\0" No_argument       "v"
 #if ENABLE_SELINUX
        "context\0" Required_argument "Z"
 #endif
-       "verbose\0" No_argument       "v"
        ;
 #endif
 
@@ -67,7 +68,7 @@
 #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
        applet_long_options = mkdir_longopts;
 #endif
-       opt = getopt32(argv, "m:p" IF_SELINUX("Z:") "v", &smode 
IF_SELINUX(,&scontext));
+       opt = getopt32(argv, "m:pv" IF_SELINUX("Z:"), &smode 
IF_SELINUX(,&scontext));
        if (opt & 1) {
                mode_t mmode = 0777;
                if (!bb_parse_mode(smode, &mmode)) {
@@ -77,8 +78,10 @@
        }
        if (opt & 2)
                flags |= FILEUTILS_RECUR;
+       if (opt & 4)
+               flags |= FILEUTILS_VERBOSE;
 #if ENABLE_SELINUX
-       if (opt & 4) {
+       if (opt & 8) {
                selinux_or_die();
                setfscreatecon_or_die(scontext);
        }
diff --git a/coreutils/mv.c b/coreutils/mv.c
index f127dfa..eff2670 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..3190c70 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 {
diff --git a/coreutils/rmdir.c b/coreutils/rmdir.c
index cc2dea0..d56b6e7 100644
--- a/coreutils/rmdir.c
+++ b/coreutils/rmdir.c
@@ -16,10 +16,12 @@
 //usage:       "Remove DIRECTORY if it is empty\n"
 //usage:       IF_FEATURE_RMDIR_LONG_OPTIONS(
 //usage:     "\n       -p|--parents    Include parents"
+//usage:     "\n       -v|--verbose    Verbose"
 //usage:     "\n       --ignore-fail-on-non-empty"
 //usage:       )
 //usage:       IF_NOT_FEATURE_RMDIR_LONG_OPTIONS(
 //usage:     "\n       -p      Include parents"
+//usage:     "\n       -v      Verbose"
 //usage:       )
 //usage:
 //usage:#define rmdir_example_usage
@@ -31,7 +33,7 @@
 
 
 #define PARENTS          (1 << 0)
-//efine VERBOSE          (1 << 1) //accepted but ignored
+#define VERBOSE          (1 << 1)
 #define IGNORE_NON_EMPTY (1 << 2)
 
 int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -62,6 +64,10 @@
                path = *argv;
 
                while (1) {
+                       if (flags & VERBOSE) {
+                               printf("rmdir: removing directory, `%s'\n", 
path);
+                       }
+
                        if (rmdir(path) < 0) {
 #if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
                                if ((flags & IGNORE_NON_EMPTY) && errno == 
ENOTEMPTY)
diff --git a/include/libbb.h b/include/libbb.h
index afdee38..100a62c 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;
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index 9333a8d..da3010d 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -389,5 +389,9 @@
                        bb_perror_msg("can't preserve %s of '%s'", 
"permissions", dest);
        }
 
+       if (flags & FILEUTILS_VERBOSE) {
+               printf("`%s' -> `%s'\n", source, dest);
+       }
+
        return retval;
 }
diff --git a/libbb/make_directory.c b/libbb/make_directory.c
index 7826b90..c7ba167 100644
--- a/libbb/make_directory.c
+++ b/libbb/make_directory.c
@@ -101,6 +101,10 @@
                        }
                }
 
+               if (flags & FILEUTILS_VERBOSE) {
+                       printf("mkdir: created directory `%s'\n", path);
+               }
+
                if (!c) {
                        /* Done.  If necessary, update perms on the newly
                         * created directory.  Failure to update here _is_
diff --git a/libbb/remove_file.c b/libbb/remove_file.c
index 5b75f7f..48121ad 100644
--- a/libbb/remove_file.c
+++ b/libbb/remove_file.c
@@ -78,6 +78,10 @@
                        return -1;
                }
 
+               if (flags & FILEUTILS_VERBOSE) {
+                       printf("removed directory: `%s'\n", path);
+               }
+
                return status;
        }
 
@@ -98,5 +102,9 @@
                return -1;
        }
 
+       if (flags & FILEUTILS_VERBOSE) {
+               printf("removed `%s'\n", path);
+       }
+
        return 0;
 }
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to