aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaro Koskinen <aaro.koskinen@iki.fi>2014-09-24 02:52:08 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2014-09-24 02:52:08 +0200
commit0f78d616cb394925d8b9511d370643ddd445adc3 (patch)
tree2a6433d4bbcead61938af489987c69af65bdb30b
parent307d26c0ebfb0d22a81070379675f6287f6e9d95 (diff)
downloadbusybox-w32-0f78d616cb394925d8b9511d370643ddd445adc3.tar.gz
busybox-w32-0f78d616cb394925d8b9511d370643ddd445adc3.tar.bz2
busybox-w32-0f78d616cb394925d8b9511d370643ddd445adc3.zip
install: implement -t DIR
Some packages want to install themselves using "-t" to specify the directory (as supported by GNU coreutils). Add support for the option for compatibility reasons. function old new delta install_longopts 76 95 +19 install_main 769 777 +8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 27/0) Total: 27 bytes Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/install.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/coreutils/install.c b/coreutils/install.c
index 6c88ae11c..6e199941e 100644
--- a/coreutils/install.c
+++ b/coreutils/install.c
@@ -8,7 +8,7 @@
8 8
9/* -v, -b, -c are ignored */ 9/* -v, -b, -c are ignored */
10//usage:#define install_trivial_usage 10//usage:#define install_trivial_usage
11//usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [SOURCE]... DEST" 11//usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [-d DIR] [SOURCE]... DEST"
12//usage:#define install_full_usage "\n\n" 12//usage:#define install_full_usage "\n\n"
13//usage: "Copy files and set attributes\n" 13//usage: "Copy files and set attributes\n"
14//usage: "\n -c Just copy (default)" 14//usage: "\n -c Just copy (default)"
@@ -19,6 +19,7 @@
19//usage: "\n -o USER Set ownership" 19//usage: "\n -o USER Set ownership"
20//usage: "\n -g GRP Set group ownership" 20//usage: "\n -g GRP Set group ownership"
21//usage: "\n -m MODE Set permissions" 21//usage: "\n -m MODE Set permissions"
22//usage: "\n -t DIR Install to DIR"
22//usage: IF_SELINUX( 23//usage: IF_SELINUX(
23//usage: "\n -Z Set security context" 24//usage: "\n -Z Set security context"
24//usage: ) 25//usage: )
@@ -37,6 +38,7 @@ static const char install_longopts[] ALIGN1 =
37 "group\0" Required_argument "g" 38 "group\0" Required_argument "g"
38 "mode\0" Required_argument "m" 39 "mode\0" Required_argument "m"
39 "owner\0" Required_argument "o" 40 "owner\0" Required_argument "o"
41 "target-directory\0" Required_argument "t"
40/* autofs build insists of using -b --suffix=.orig */ 42/* autofs build insists of using -b --suffix=.orig */
41/* TODO? (short option for --suffix is -S) */ 43/* TODO? (short option for --suffix is -S) */
42#if ENABLE_SELINUX 44#if ENABLE_SELINUX
@@ -95,9 +97,8 @@ int install_main(int argc, char **argv)
95 int mkdir_flags = FILEUTILS_RECUR; 97 int mkdir_flags = FILEUTILS_RECUR;
96 int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; 98 int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
97 int opts; 99 int opts;
98 int min_args = 1;
99 int ret = EXIT_SUCCESS; 100 int ret = EXIT_SUCCESS;
100 int isdir = 0; 101 int isdir;
101#if ENABLE_SELINUX 102#if ENABLE_SELINUX
102 security_context_t scontext; 103 security_context_t scontext;
103 bool use_default_selinux_context = 1; 104 bool use_default_selinux_context = 1;
@@ -113,20 +114,22 @@ int install_main(int argc, char **argv)
113 OPT_GROUP = 1 << 7, 114 OPT_GROUP = 1 << 7,
114 OPT_MODE = 1 << 8, 115 OPT_MODE = 1 << 8,
115 OPT_OWNER = 1 << 9, 116 OPT_OWNER = 1 << 9,
117 OPT_TARGET = 1 << 10,
116#if ENABLE_SELINUX 118#if ENABLE_SELINUX
117 OPT_SET_SECURITY_CONTEXT = 1 << 10, 119 OPT_SET_SECURITY_CONTEXT = 1 << 11,
118 OPT_PRESERVE_SECURITY_CONTEXT = 1 << 11, 120 OPT_PRESERVE_SECURITY_CONTEXT = 1 << 12,
119#endif 121#endif
120 }; 122 };
121 123
122#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS 124#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
123 applet_long_options = install_longopts; 125 applet_long_options = install_longopts;
124#endif 126#endif
125 opt_complementary = "s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z")); 127 opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
126 /* -c exists for backwards compatibility, it's needed */ 128 /* -c exists for backwards compatibility, it's needed */
127 /* -b is ignored ("make a backup of each existing destination file") */ 129 /* -b is ignored ("make a backup of each existing destination file") */
128 opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"), 130 opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"),
129 &gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext)); 131 &gid_str, &mode_str, &uid_str, &last
132 IF_SELINUX(, &scontext));
130 argc -= optind; 133 argc -= optind;
131 argv += optind; 134 argv += optind;
132 135
@@ -160,20 +163,23 @@ int install_main(int argc, char **argv)
160 uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid(); 163 uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
161 gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid(); 164 gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
162 165
163 last = argv[argc - 1]; 166 /* If -t DIR is in use, then isdir=true, last="DIR" */
164 if (!(opts & OPT_DIRECTORY)) { 167 isdir = (opts & OPT_TARGET);
165 argv[argc - 1] = NULL; 168 if (!(opts & (OPT_TARGET|OPT_DIRECTORY))) {
166 min_args++; 169 /* Neither -t DIR nor -d is in use */
167 170 argc--;
171 last = argv[argc];
172 argv[argc] = NULL;
168 /* coreutils install resolves link in this case, don't use lstat */ 173 /* coreutils install resolves link in this case, don't use lstat */
169 isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode); 174 isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
170 } 175 }
171 176
172 if (argc < min_args) 177 if (argc < 1)
173 bb_show_usage(); 178 bb_show_usage();
174 179
175 while ((arg = *argv++) != NULL) { 180 while ((arg = *argv++) != NULL) {
176 char *dest = last; 181 char *dest;
182
177 if (opts & OPT_DIRECTORY) { 183 if (opts & OPT_DIRECTORY) {
178 dest = arg; 184 dest = arg;
179 /* GNU coreutils 6.9 does not set uid:gid 185 /* GNU coreutils 6.9 does not set uid:gid
@@ -184,6 +190,7 @@ int install_main(int argc, char **argv)
184 goto next; 190 goto next;
185 } 191 }
186 } else { 192 } else {
193 dest = last;
187 if (opts & OPT_MKDIR_LEADING) { 194 if (opts & OPT_MKDIR_LEADING) {
188 char *ddir = xstrdup(dest); 195 char *ddir = xstrdup(dest);
189 bb_make_directory(dirname(ddir), 0755, mkdir_flags); 196 bb_make_directory(dirname(ddir), 0755, mkdir_flags);