Remove unneeded conditions and logic, fix bug where ownership didnt
change. Dont use bb_make_directory it doesnt have the features, and its ugly to work around it.
This commit is contained in:
parent
475820c9de
commit
578eff5066
@ -42,12 +42,12 @@
|
||||
extern int install_main(int argc, char **argv)
|
||||
{
|
||||
struct stat statbuf;
|
||||
mode_t mode = 0755;
|
||||
uid_t uid = -1;
|
||||
gid_t gid = -1;
|
||||
char *gid_str;
|
||||
char *uid_str;
|
||||
char *mode_str;
|
||||
mode_t mode;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
char *gid_str = "-1";
|
||||
char *uid_str = "-1";
|
||||
char *mode_str = "0755";
|
||||
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
|
||||
int ret = EXIT_SUCCESS;
|
||||
int flags;
|
||||
@ -60,39 +60,40 @@ extern int install_main(int argc, char **argv)
|
||||
if (flags & INSTALL_OPT_PRESERVE_TIME) {
|
||||
copy_flags |= FILEUTILS_PRESERVE_STATUS;
|
||||
}
|
||||
if (flags & INSTALL_OPT_GROUP) {
|
||||
gid = get_ug_id(gid_str, my_getgrnam);
|
||||
}
|
||||
if (flags & INSTALL_OPT_MODE) {
|
||||
bb_parse_mode(mode_str, &mode);
|
||||
}
|
||||
if (flags & INSTALL_OPT_OWNER) {
|
||||
gid = get_ug_id(gid_str, my_getgrnam);
|
||||
uid = get_ug_id(uid_str, my_getpwnam);
|
||||
}
|
||||
umask(0);
|
||||
|
||||
/* Create directories */
|
||||
/* Create directories
|
||||
* dont use bb_make_directory() as it cant change uid or gid
|
||||
* perhaps bb_make_directory() should be improved.
|
||||
*/
|
||||
if (flags & INSTALL_OPT_DIRECTORY) {
|
||||
|
||||
for (argv += optind; *argv; argv++) {
|
||||
unsigned char *dir_name = *argv;
|
||||
unsigned char *argv_ptr;
|
||||
|
||||
ret |= bb_make_directory(dir_name, mode, FILEUTILS_RECUR);
|
||||
char *old_argv_ptr = *argv + 1;
|
||||
char *argv_ptr;
|
||||
do {
|
||||
argv_ptr = strrchr(dir_name, '/');
|
||||
|
||||
/* Skip the "." and ".." directories */
|
||||
if ((dir_name[0] == '.') && ((dir_name[1] == '\0') || ((dir_name[1] == '.') && (dir_name[2] == '\0')))) {
|
||||
break;
|
||||
}
|
||||
if (lchown(dir_name, uid, gid) == -1) {
|
||||
bb_perror_msg("cannot change ownership of %s", argv_ptr);
|
||||
ret |= EXIT_FAILURE;
|
||||
}
|
||||
argv_ptr = strchr(old_argv_ptr, '/');
|
||||
old_argv_ptr = argv_ptr;
|
||||
if (argv_ptr) {
|
||||
*argv_ptr = '\0';
|
||||
old_argv_ptr++;
|
||||
}
|
||||
} while (argv_ptr);
|
||||
if ((mkdir(*argv, mode) == -1) && (errno != EEXIST)) {
|
||||
bb_perror_msg("coulnt create %s", *argv);
|
||||
ret = EXIT_FAILURE;
|
||||
break;
|
||||
}
|
||||
else if (lchown(*argv, uid, gid) == -1) {
|
||||
bb_perror_msg("cannot change ownership of %s", *argv);
|
||||
ret = EXIT_FAILURE;
|
||||
break;
|
||||
}
|
||||
if (argv_ptr) {
|
||||
*argv_ptr = '/';
|
||||
}
|
||||
} while (old_argv_ptr);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
@ -111,18 +112,18 @@ extern int install_main(int argc, char **argv)
|
||||
/* Set the file mode */
|
||||
if (chmod(dest, mode) == -1) {
|
||||
bb_perror_msg("cannot change permissions of %s", dest);
|
||||
ret |= EXIT_FAILURE;
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Set the user and group id */
|
||||
if (lchown(dest, uid, gid) == -1) {
|
||||
bb_perror_msg("cannot change ownership of %s", dest);
|
||||
ret |= EXIT_FAILURE;
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
if (flags & INSTALL_OPT_STRIP) {
|
||||
if (execlp("strip", "strip", dest, NULL) == -1) {
|
||||
bb_error_msg("strip failed");
|
||||
ret |= EXIT_FAILURE;
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user