diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2004-01-23 10:57:00 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2004-01-23 10:57:00 +0000 |
commit | 578eff50667a2192905c68073f97bc6aa21cebe7 (patch) | |
tree | aa08adcf3b62c0ca7bdc23adab04d43abdce7007 /coreutils/install.c | |
parent | 475820c9de166bd8bcb7b3c3acabdba0204a2360 (diff) | |
download | busybox-w32-578eff50667a2192905c68073f97bc6aa21cebe7.tar.gz busybox-w32-578eff50667a2192905c68073f97bc6aa21cebe7.tar.bz2 busybox-w32-578eff50667a2192905c68073f97bc6aa21cebe7.zip |
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/install.c')
-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 @@ | |||
42 | extern int install_main(int argc, char **argv) | 42 | extern int install_main(int argc, char **argv) |
43 | { | 43 | { |
44 | struct stat statbuf; | 44 | struct stat statbuf; |
45 | mode_t mode = 0755; | 45 | mode_t mode; |
46 | uid_t uid = -1; | 46 | uid_t uid; |
47 | gid_t gid = -1; | 47 | gid_t gid; |
48 | char *gid_str; | 48 | char *gid_str = "-1"; |
49 | char *uid_str; | 49 | char *uid_str = "-1"; |
50 | char *mode_str; | 50 | char *mode_str = "0755"; |
51 | int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; | 51 | int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; |
52 | int ret = EXIT_SUCCESS; | 52 | int ret = EXIT_SUCCESS; |
53 | int flags; | 53 | int flags; |
@@ -60,39 +60,40 @@ extern int install_main(int argc, char **argv) | |||
60 | if (flags & INSTALL_OPT_PRESERVE_TIME) { | 60 | if (flags & INSTALL_OPT_PRESERVE_TIME) { |
61 | copy_flags |= FILEUTILS_PRESERVE_STATUS; | 61 | copy_flags |= FILEUTILS_PRESERVE_STATUS; |
62 | } | 62 | } |
63 | if (flags & INSTALL_OPT_GROUP) { | 63 | bb_parse_mode(mode_str, &mode); |
64 | gid = get_ug_id(gid_str, my_getgrnam); | 64 | gid = get_ug_id(gid_str, my_getgrnam); |
65 | } | 65 | uid = get_ug_id(uid_str, my_getpwnam); |
66 | if (flags & INSTALL_OPT_MODE) { | 66 | umask(0); |
67 | bb_parse_mode(mode_str, &mode); | ||
68 | } | ||
69 | if (flags & INSTALL_OPT_OWNER) { | ||
70 | uid = get_ug_id(uid_str, my_getpwnam); | ||
71 | } | ||
72 | 67 | ||
73 | /* Create directories */ | 68 | /* Create directories |
69 | * dont use bb_make_directory() as it cant change uid or gid | ||
70 | * perhaps bb_make_directory() should be improved. | ||
71 | */ | ||
74 | if (flags & INSTALL_OPT_DIRECTORY) { | 72 | if (flags & INSTALL_OPT_DIRECTORY) { |
75 | |||
76 | for (argv += optind; *argv; argv++) { | 73 | for (argv += optind; *argv; argv++) { |
77 | unsigned char *dir_name = *argv; | 74 | char *old_argv_ptr = *argv + 1; |
78 | unsigned char *argv_ptr; | 75 | char *argv_ptr; |
79 | |||
80 | ret |= bb_make_directory(dir_name, mode, FILEUTILS_RECUR); | ||
81 | do { | 76 | do { |
82 | argv_ptr = strrchr(dir_name, '/'); | 77 | argv_ptr = strchr(old_argv_ptr, '/'); |
83 | 78 | old_argv_ptr = argv_ptr; | |
84 | /* Skip the "." and ".." directories */ | 79 | if (argv_ptr) { |
85 | if ((dir_name[0] == '.') && ((dir_name[1] == '\0') || ((dir_name[1] == '.') && (dir_name[2] == '\0')))) { | 80 | *argv_ptr = '\0'; |
81 | old_argv_ptr++; | ||
82 | } | ||
83 | if ((mkdir(*argv, mode) == -1) && (errno != EEXIST)) { | ||
84 | bb_perror_msg("coulnt create %s", *argv); | ||
85 | ret = EXIT_FAILURE; | ||
86 | break; | 86 | break; |
87 | } | 87 | } |
88 | if (lchown(dir_name, uid, gid) == -1) { | 88 | else if (lchown(*argv, uid, gid) == -1) { |
89 | bb_perror_msg("cannot change ownership of %s", argv_ptr); | 89 | bb_perror_msg("cannot change ownership of %s", *argv); |
90 | ret |= EXIT_FAILURE; | 90 | ret = EXIT_FAILURE; |
91 | break; | ||
91 | } | 92 | } |
92 | if (argv_ptr) { | 93 | if (argv_ptr) { |
93 | *argv_ptr = '\0'; | 94 | *argv_ptr = '/'; |
94 | } | 95 | } |
95 | } while (argv_ptr); | 96 | } while (old_argv_ptr); |
96 | } | 97 | } |
97 | return(ret); | 98 | return(ret); |
98 | } | 99 | } |
@@ -111,18 +112,18 @@ extern int install_main(int argc, char **argv) | |||
111 | /* Set the file mode */ | 112 | /* Set the file mode */ |
112 | if (chmod(dest, mode) == -1) { | 113 | if (chmod(dest, mode) == -1) { |
113 | bb_perror_msg("cannot change permissions of %s", dest); | 114 | bb_perror_msg("cannot change permissions of %s", dest); |
114 | ret |= EXIT_FAILURE; | 115 | ret = EXIT_FAILURE; |
115 | } | 116 | } |
116 | 117 | ||
117 | /* Set the user and group id */ | 118 | /* Set the user and group id */ |
118 | if (lchown(dest, uid, gid) == -1) { | 119 | if (lchown(dest, uid, gid) == -1) { |
119 | bb_perror_msg("cannot change ownership of %s", dest); | 120 | bb_perror_msg("cannot change ownership of %s", dest); |
120 | ret |= EXIT_FAILURE; | 121 | ret = EXIT_FAILURE; |
121 | } | 122 | } |
122 | if (flags & INSTALL_OPT_STRIP) { | 123 | if (flags & INSTALL_OPT_STRIP) { |
123 | if (execlp("strip", "strip", dest, NULL) == -1) { | 124 | if (execlp("strip", "strip", dest, NULL) == -1) { |
124 | bb_error_msg("strip failed"); | 125 | bb_error_msg("strip failed"); |
125 | ret |= EXIT_FAILURE; | 126 | ret = EXIT_FAILURE; |
126 | } | 127 | } |
127 | } | 128 | } |
128 | } | 129 | } |