diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2004-01-23 13:57:00 +0300 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2004-01-23 13:57:00 +0300 |
commit | 578eff50667a2192905c68073f97bc6aa21cebe7 (patch) | |
tree | aa08adcf3b62c0ca7bdc23adab04d43abdce7007 /coreutils | |
parent | 475820c9de166bd8bcb7b3c3acabdba0204a2360 (diff) |
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.
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/install.c | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/coreutils/install.c b/coreutils/install.c index 9a1306746..657962c51 100644 --- a/coreutils/install.c +++ b/coreutils/install.c @@ -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) { - uid = get_ug_id(uid_str, my_getpwnam); - } + bb_parse_mode(mode_str, &mode); + 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')))) { + argv_ptr = strchr(old_argv_ptr, '/'); + old_argv_ptr = argv_ptr; + if (argv_ptr) { + *argv_ptr = '\0'; + old_argv_ptr++; + } + if ((mkdir(*argv, mode) == -1) && (errno != EEXIST)) { + bb_perror_msg("coulnt create %s", *argv); + ret = EXIT_FAILURE; break; } - if (lchown(dir_name, uid, gid) == -1) { - bb_perror_msg("cannot change ownership of %s", argv_ptr); - ret |= EXIT_FAILURE; + 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 = '\0'; + *argv_ptr = '/'; } - } while (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; } } } |