aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-05-19 16:23:50 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2014-05-19 16:23:50 +0200
commit17f8418ea75410c3fbf9c9558f50f22cb8808e3e (patch)
tree9b9a7d6296ffb77c8b855eb34b8cbf03b960e005
parent539e2802ebd2680602de0a2c76069b7f555392d9 (diff)
downloadbusybox-w32-17f8418ea75410c3fbf9c9558f50f22cb8808e3e.tar.gz
busybox-w32-17f8418ea75410c3fbf9c9558f50f22cb8808e3e.tar.bz2
busybox-w32-17f8418ea75410c3fbf9c9558f50f22cb8808e3e.zip
Add conditional support for -v / --verbose
With FEATURE_VERBOSE off, practically no size change. With it on: function old new delta remove_file 493 556 +63 install_main 719 765 +46 bb_make_directory 383 419 +36 rmdir_main 162 191 +29 copy_file 1516 1544 +28 mv_main 502 525 +23 cmp_main 677 693 +16 bbconfig_config_bz2 5264 5279 +15 mkdir_main 158 168 +10 install_longopts 66 76 +10 rm_main 167 175 +8 nexpr 840 846 +6 scan_tree 275 280 +5 fsck_main 1807 1811 +4 ed_main 2541 2545 +4 expand_one_var 1574 1575 +1 swap_on_off_main 420 418 -2 parse_command 1443 1440 -3 redirect 1279 1274 -5 do_load 946 918 -28 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 16/4 up/down: 304/-38) Total: 266 bytes Based on the patch by Igor Živković. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/Config.src10
-rw-r--r--coreutils/cp.c1
-rw-r--r--coreutils/install.c14
-rw-r--r--coreutils/mkdir.c8
-rw-r--r--coreutils/mv.c8
-rw-r--r--coreutils/rm.c3
-rw-r--r--coreutils/rmdir.c10
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/copy_file.c4
-rw-r--r--libbb/make_directory.c4
-rw-r--r--libbb/remove_file.c8
11 files changed, 62 insertions, 10 deletions
diff --git a/coreutils/Config.src b/coreutils/Config.src
index 33defa4db..68c717883 100644
--- a/coreutils/Config.src
+++ b/coreutils/Config.src
@@ -739,6 +739,16 @@ config YES
739 yes is used to repeatedly output a specific string, or 739 yes is used to repeatedly output a specific string, or
740 the default string `y'. 740 the default string `y'.
741 741
742comment "Common options"
743
744config FEATURE_VERBOSE
745 bool "Support verbose options (usually -v) for various applets"
746 default y
747 help
748 Enable cp -v, rm -v and similar messages.
749 Also enables long option (--verbose) if it exists.
750 Without this option, -v is accepted but ignored.
751
742comment "Common options for cp and mv" 752comment "Common options for cp and mv"
743 depends on CP || MV 753 depends on CP || MV
744 754
diff --git a/coreutils/cp.c b/coreutils/cp.c
index de2e512be..247ed0fda 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -79,7 +79,6 @@ int cp_main(int argc, char **argv)
79 "parents\0" No_argument "\xff" 79 "parents\0" No_argument "\xff"
80 ; 80 ;
81#endif 81#endif
82 // -v (--verbose) is ignored
83 flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv"); 82 flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
84 /* Options of cp from GNU coreutils 6.10: 83 /* Options of cp from GNU coreutils 6.10:
85 * -a, --archive 84 * -a, --archive
diff --git a/coreutils/install.c b/coreutils/install.c
index 445497f9a..6c88ae11c 100644
--- a/coreutils/install.c
+++ b/coreutils/install.c
@@ -28,6 +28,9 @@
28 28
29#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS 29#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
30static const char install_longopts[] ALIGN1 = 30static const char install_longopts[] ALIGN1 =
31 IF_FEATURE_VERBOSE(
32 "verbose\0" No_argument "v"
33 )
31 "directory\0" No_argument "d" 34 "directory\0" No_argument "d"
32 "preserve-timestamps\0" No_argument "p" 35 "preserve-timestamps\0" No_argument "p"
33 "strip\0" No_argument "s" 36 "strip\0" No_argument "s"
@@ -89,6 +92,7 @@ int install_main(int argc, char **argv)
89 const char *gid_str; 92 const char *gid_str;
90 const char *uid_str; 93 const char *uid_str;
91 const char *mode_str; 94 const char *mode_str;
95 int mkdir_flags = FILEUTILS_RECUR;
92 int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; 96 int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
93 int opts; 97 int opts;
94 int min_args = 1; 98 int min_args = 1;
@@ -120,7 +124,6 @@ int install_main(int argc, char **argv)
120#endif 124#endif
121 opt_complementary = "s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z")); 125 opt_complementary = "s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
122 /* -c exists for backwards compatibility, it's needed */ 126 /* -c exists for backwards compatibility, it's needed */
123 /* -v is ignored ("print name of each created directory") */
124 /* -b is ignored ("make a backup of each existing destination file") */ 127 /* -b is ignored ("make a backup of each existing destination file") */
125 opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"), 128 opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"),
126 &gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext)); 129 &gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext));
@@ -141,6 +144,11 @@ int install_main(int argc, char **argv)
141 } 144 }
142#endif 145#endif
143 146
147 if ((opts & OPT_v) && FILEUTILS_VERBOSE) {
148 mkdir_flags |= FILEUTILS_VERBOSE;
149 copy_flags |= FILEUTILS_VERBOSE;
150 }
151
144 /* preserve access and modification time, this is GNU behaviour, 152 /* preserve access and modification time, this is GNU behaviour,
145 * BSD only preserves modification time */ 153 * BSD only preserves modification time */
146 if (opts & OPT_PRESERVE_TIME) { 154 if (opts & OPT_PRESERVE_TIME) {
@@ -171,14 +179,14 @@ int install_main(int argc, char **argv)
171 /* GNU coreutils 6.9 does not set uid:gid 179 /* GNU coreutils 6.9 does not set uid:gid
172 * on intermediate created directories 180 * on intermediate created directories
173 * (only on last one) */ 181 * (only on last one) */
174 if (bb_make_directory(dest, 0755, FILEUTILS_RECUR)) { 182 if (bb_make_directory(dest, 0755, mkdir_flags)) {
175 ret = EXIT_FAILURE; 183 ret = EXIT_FAILURE;
176 goto next; 184 goto next;
177 } 185 }
178 } else { 186 } else {
179 if (opts & OPT_MKDIR_LEADING) { 187 if (opts & OPT_MKDIR_LEADING) {
180 char *ddir = xstrdup(dest); 188 char *ddir = xstrdup(dest);
181 bb_make_directory(dirname(ddir), 0755, FILEUTILS_RECUR); 189 bb_make_directory(dirname(ddir), 0755, mkdir_flags);
182 /* errors are not checked. copy_file 190 /* errors are not checked. copy_file
183 * will fail if dir is not created. */ 191 * will fail if dir is not created. */
184 free(ddir); 192 free(ddir);
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c
index 4a8e43e43..864edfb0a 100644
--- a/coreutils/mkdir.c
+++ b/coreutils/mkdir.c
@@ -48,7 +48,9 @@ static const char mkdir_longopts[] ALIGN1 =
48#if ENABLE_SELINUX 48#if ENABLE_SELINUX
49 "context\0" Required_argument "Z" 49 "context\0" Required_argument "Z"
50#endif 50#endif
51#if ENABLE_FEATURE_VERBOSE
51 "verbose\0" No_argument "v" 52 "verbose\0" No_argument "v"
53#endif
52 ; 54 ;
53#endif 55#endif
54 56
@@ -67,7 +69,7 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv)
67#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS 69#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
68 applet_long_options = mkdir_longopts; 70 applet_long_options = mkdir_longopts;
69#endif 71#endif
70 opt = getopt32(argv, "m:p" IF_SELINUX("Z:") "v", &smode IF_SELINUX(,&scontext)); 72 opt = getopt32(argv, "m:pv" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
71 if (opt & 1) { 73 if (opt & 1) {
72 mode_t mmode = 0777; 74 mode_t mmode = 0777;
73 if (!bb_parse_mode(smode, &mmode)) { 75 if (!bb_parse_mode(smode, &mmode)) {
@@ -77,8 +79,10 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv)
77 } 79 }
78 if (opt & 2) 80 if (opt & 2)
79 flags |= FILEUTILS_RECUR; 81 flags |= FILEUTILS_RECUR;
82 if ((opt & 4) && FILEUTILS_VERBOSE)
83 flags |= FILEUTILS_VERBOSE;
80#if ENABLE_SELINUX 84#if ENABLE_SELINUX
81 if (opt & 4) { 85 if (opt & 8) {
82 selinux_or_die(); 86 selinux_or_die();
83 setfscreatecon_or_die(scontext); 87 setfscreatecon_or_die(scontext);
84 } 88 }
diff --git a/coreutils/mv.c b/coreutils/mv.c
index f127dfabd..50571755b 100644
--- a/coreutils/mv.c
+++ b/coreutils/mv.c
@@ -33,13 +33,17 @@ static const char mv_longopts[] ALIGN1 =
33 "interactive\0" No_argument "i" 33 "interactive\0" No_argument "i"
34 "force\0" No_argument "f" 34 "force\0" No_argument "f"
35 "no-clobber\0" No_argument "n" 35 "no-clobber\0" No_argument "n"
36 IF_FEATURE_VERBOSE(
36 "verbose\0" No_argument "v" 37 "verbose\0" No_argument "v"
38 )
37 ; 39 ;
38#endif 40#endif
39 41
40#define OPT_FORCE (1 << 0) 42#define OPT_FORCE (1 << 0)
41#define OPT_INTERACTIVE (1 << 1) 43#define OPT_INTERACTIVE (1 << 1)
42#define OPT_NOCLOBBER (1 << 2) 44#define OPT_NOCLOBBER (1 << 2)
45#define OPT_VERBOSE ((1 << 3) * ENABLE_FEATURE_VERBOSE)
46
43 47
44int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 48int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
45int mv_main(int argc, char **argv) 49int mv_main(int argc, char **argv)
@@ -58,7 +62,6 @@ int mv_main(int argc, char **argv)
58 /* Need at least two arguments. 62 /* Need at least two arguments.
59 * If more than one of -f, -i, -n is specified , only the final one 63 * If more than one of -f, -i, -n is specified , only the final one
60 * takes effect (it unsets previous options). 64 * takes effect (it unsets previous options).
61 * -v is accepted but ignored.
62 */ 65 */
63 opt_complementary = "-2:f-in:i-fn:n-fi"; 66 opt_complementary = "-2:f-in:i-fn:n-fi";
64 flags = getopt32(argv, "finv"); 67 flags = getopt32(argv, "finv");
@@ -148,6 +151,9 @@ int mv_main(int argc, char **argv)
148 status = 1; 151 status = 1;
149 } 152 }
150 RET_0: 153 RET_0:
154 if (flags & OPT_VERBOSE) {
155 printf("'%s' -> '%s'\n", *argv, dest);
156 }
151 if (dest != last) { 157 if (dest != last) {
152 free((void *) dest); 158 free((void *) dest);
153 } 159 }
diff --git a/coreutils/rm.c b/coreutils/rm.c
index 042fba162..d0ad81dfc 100644
--- a/coreutils/rm.c
+++ b/coreutils/rm.c
@@ -38,7 +38,6 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
38 unsigned opt; 38 unsigned opt;
39 39
40 opt_complementary = "f-i:i-f"; 40 opt_complementary = "f-i:i-f";
41 /* -v (verbose) is ignored */
42 opt = getopt32(argv, "fiRrv"); 41 opt = getopt32(argv, "fiRrv");
43 argv += optind; 42 argv += optind;
44 if (opt & 1) 43 if (opt & 1)
@@ -47,6 +46,8 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
47 flags |= FILEUTILS_INTERACTIVE; 46 flags |= FILEUTILS_INTERACTIVE;
48 if (opt & (8|4)) 47 if (opt & (8|4))
49 flags |= FILEUTILS_RECUR; 48 flags |= FILEUTILS_RECUR;
49 if ((opt & 16) && FILEUTILS_VERBOSE)
50 flags |= FILEUTILS_VERBOSE;
50 51
51 if (*argv != NULL) { 52 if (*argv != NULL) {
52 do { 53 do {
diff --git a/coreutils/rmdir.c b/coreutils/rmdir.c
index cc2dea010..0792a1c8e 100644
--- a/coreutils/rmdir.c
+++ b/coreutils/rmdir.c
@@ -31,7 +31,7 @@
31 31
32 32
33#define PARENTS (1 << 0) 33#define PARENTS (1 << 0)
34//efine VERBOSE (1 << 1) //accepted but ignored 34#define VERBOSE ((1 << 1) * ENABLE_FEATURE_VERBOSE)
35#define IGNORE_NON_EMPTY (1 << 2) 35#define IGNORE_NON_EMPTY (1 << 2)
36 36
37int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 37int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -44,10 +44,12 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
44#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS 44#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
45 static const char rmdir_longopts[] ALIGN1 = 45 static const char rmdir_longopts[] ALIGN1 =
46 "parents\0" No_argument "p" 46 "parents\0" No_argument "p"
47 "verbose\0" No_argument "v"
48 /* Debian etch: many packages fail to be purged or installed 47 /* Debian etch: many packages fail to be purged or installed
49 * because they desperately want this option: */ 48 * because they desperately want this option: */
50 "ignore-fail-on-non-empty\0" No_argument "\xff" 49 "ignore-fail-on-non-empty\0" No_argument "\xff"
50 IF_FEATURE_VERBOSE(
51 "verbose\0" No_argument "v"
52 )
51 ; 53 ;
52 applet_long_options = rmdir_longopts; 54 applet_long_options = rmdir_longopts;
53#endif 55#endif
@@ -62,6 +64,10 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
62 path = *argv; 64 path = *argv;
63 65
64 while (1) { 66 while (1) {
67 if (flags & VERBOSE) {
68 printf("rmdir: removing directory, '%s'\n", path);
69 }
70
65 if (rmdir(path) < 0) { 71 if (rmdir(path) < 0) {
66#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS 72#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
67 if ((flags & IGNORE_NON_EMPTY) && errno == ENOTEMPTY) 73 if ((flags & IGNORE_NON_EMPTY) && errno == ENOTEMPTY)
diff --git a/include/libbb.h b/include/libbb.h
index afdee38c4..a1a0dc18c 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -334,6 +334,8 @@ enum { /* DO NOT CHANGE THESE VALUES! cp.c, mv.c, install.c depend on them. */
334 FILEUTILS_SET_SECURITY_CONTEXT = 1 << 10, 334 FILEUTILS_SET_SECURITY_CONTEXT = 1 << 10,
335#endif 335#endif
336 FILEUTILS_IGNORE_CHMOD_ERR = 1 << 11, 336 FILEUTILS_IGNORE_CHMOD_ERR = 1 << 11,
337 /* -v */
338 FILEUTILS_VERBOSE = (1 << 12) * ENABLE_FEATURE_VERBOSE,
337}; 339};
338#define FILEUTILS_CP_OPTSTR "pdRfilsLH" IF_SELINUX("c") 340#define FILEUTILS_CP_OPTSTR "pdRfilsLH" IF_SELINUX("c")
339extern int remove_file(const char *path, int flags) FAST_FUNC; 341extern int remove_file(const char *path, int flags) FAST_FUNC;
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index 9333a8d49..a4be875d2 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -389,5 +389,9 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
389 bb_perror_msg("can't preserve %s of '%s'", "permissions", dest); 389 bb_perror_msg("can't preserve %s of '%s'", "permissions", dest);
390 } 390 }
391 391
392 if (flags & FILEUTILS_VERBOSE) {
393 printf("'%s' -> '%s'\n", source, dest);
394 }
395
392 return retval; 396 return retval;
393} 397}
diff --git a/libbb/make_directory.c b/libbb/make_directory.c
index 7826b90f5..89352ca1f 100644
--- a/libbb/make_directory.c
+++ b/libbb/make_directory.c
@@ -99,6 +99,10 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags)
99 if (!c) { 99 if (!c) {
100 goto ret0; 100 goto ret0;
101 } 101 }
102 } else {
103 if (flags & FILEUTILS_VERBOSE) {
104 printf("created directory: '%s'\n", path);
105 }
102 } 106 }
103 107
104 if (!c) { 108 if (!c) {
diff --git a/libbb/remove_file.c b/libbb/remove_file.c
index 5b75f7f30..eaca293d9 100644
--- a/libbb/remove_file.c
+++ b/libbb/remove_file.c
@@ -78,6 +78,10 @@ int FAST_FUNC remove_file(const char *path, int flags)
78 return -1; 78 return -1;
79 } 79 }
80 80
81 if (flags & FILEUTILS_VERBOSE) {
82 printf("removed directory: '%s'\n", path);
83 }
84
81 return status; 85 return status;
82 } 86 }
83 87
@@ -98,5 +102,9 @@ int FAST_FUNC remove_file(const char *path, int flags)
98 return -1; 102 return -1;
99 } 103 }
100 104
105 if (flags & FILEUTILS_VERBOSE) {
106 printf("removed '%s'\n", path);
107 }
108
101 return 0; 109 return 0;
102} 110}