Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/coreutils/install.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/coreutils/install.c
r3232 r3621 9 9 /* -v, -b, -c are ignored */ 10 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] [-t DIR] [SOURCE]... DEST" 12 12 //usage:#define install_full_usage "\n\n" 13 13 //usage: "Copy files and set attributes\n" … … 20 20 //usage: "\n -g GRP Set group ownership" 21 21 //usage: "\n -m MODE Set permissions" 22 //usage: "\n -t DIR Install to DIR" 22 23 //usage: IF_SELINUX( 23 24 //usage: "\n -Z Set security context" … … 29 30 #if ENABLE_FEATURE_INSTALL_LONG_OPTIONS 30 31 static const char install_longopts[] ALIGN1 = 32 IF_FEATURE_VERBOSE( 33 "verbose\0" No_argument "v" 34 ) 31 35 "directory\0" No_argument "d" 32 36 "preserve-timestamps\0" No_argument "p" … … 35 39 "mode\0" Required_argument "m" 36 40 "owner\0" Required_argument "o" 41 "target-directory\0" Required_argument "t" 37 42 /* autofs build insists of using -b --suffix=.orig */ 38 43 /* TODO? (short option for --suffix is -S) */ … … 90 95 const char *uid_str; 91 96 const char *mode_str; 97 int mkdir_flags = FILEUTILS_RECUR; 92 98 int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; 93 99 int opts; 94 int min_args = 1;95 100 int ret = EXIT_SUCCESS; 96 int isdir = 0;101 int isdir; 97 102 #if ENABLE_SELINUX 98 103 security_context_t scontext; … … 110 115 OPT_MODE = 1 << 8, 111 116 OPT_OWNER = 1 << 9, 112 #if ENABLE_SELINUX 113 OPT_SET_SECURITY_CONTEXT = 1 << 10, 114 OPT_PRESERVE_SECURITY_CONTEXT = 1 << 11, 117 OPT_TARGET = 1 << 10, 118 #if ENABLE_SELINUX 119 OPT_SET_SECURITY_CONTEXT = 1 << 11, 120 OPT_PRESERVE_SECURITY_CONTEXT = 1 << 12, 115 121 #endif 116 122 }; … … 119 125 applet_long_options = install_longopts; 120 126 #endif 121 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")); 122 128 /* -c exists for backwards compatibility, it's needed */ 123 /* -v is ignored ("print name of each created directory") */124 129 /* -b is ignored ("make a backup of each existing destination file") */ 125 opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"), 126 &gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext)); 130 opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"), 131 &gid_str, &mode_str, &uid_str, &last 132 IF_SELINUX(, &scontext)); 127 133 argc -= optind; 128 134 argv += optind; … … 142 148 #endif 143 149 150 if ((opts & OPT_v) && FILEUTILS_VERBOSE) { 151 mkdir_flags |= FILEUTILS_VERBOSE; 152 copy_flags |= FILEUTILS_VERBOSE; 153 } 154 144 155 /* preserve access and modification time, this is GNU behaviour, 145 156 * BSD only preserves modification time */ … … 149 160 mode = 0755; /* GNU coreutils 6.10 compat */ 150 161 if (opts & OPT_MODE) 151 bb_parse_mode(mode_str, &mode);162 mode = bb_parse_mode(mode_str, mode); 152 163 uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid(); 153 164 gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid(); 154 165 155 last = argv[argc - 1]; 156 if (!(opts & OPT_DIRECTORY)) { 157 argv[argc - 1] = NULL; 158 min_args++; 159 166 /* If -t DIR is in use, then isdir=true, last="DIR" */ 167 isdir = (opts & OPT_TARGET); 168 if (!(opts & (OPT_TARGET|OPT_DIRECTORY))) { 169 /* Neither -t DIR nor -d is in use */ 170 argc--; 171 last = argv[argc]; 172 argv[argc] = NULL; 160 173 /* coreutils install resolves link in this case, don't use lstat */ 161 174 isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode); 162 175 } 163 176 164 if (argc < min_args)177 if (argc < 1) 165 178 bb_show_usage(); 166 179 167 180 while ((arg = *argv++) != NULL) { 168 char *dest = last; 181 char *dest; 182 169 183 if (opts & OPT_DIRECTORY) { 170 184 dest = arg; … … 172 186 * on intermediate created directories 173 187 * (only on last one) */ 174 if (bb_make_directory(dest, 0755, FILEUTILS_RECUR)) {188 if (bb_make_directory(dest, 0755, mkdir_flags)) { 175 189 ret = EXIT_FAILURE; 176 190 goto next; 177 191 } 178 192 } else { 193 dest = last; 179 194 if (opts & OPT_MKDIR_LEADING) { 180 195 char *ddir = xstrdup(dest); 181 bb_make_directory(dirname(ddir), 0755, FILEUTILS_RECUR);196 bb_make_directory(dirname(ddir), 0755, mkdir_flags); 182 197 /* errors are not checked. copy_file 183 198 * will fail if dir is not created. */
Note:
See TracChangeset
for help on using the changeset viewer.