[BusyBox] problem with coreutils install
William Barsse
wbarsse at pfn.com
Fri Jan 23 15:53:46 UTC 2004
Hi Glenn,
I like the solution. Thanks for the feedback, however there is one
thing that bugs me (though I haven't checked if the GNU install does it
that way) : Should the ownership be changed on directories that haven't
been created by the command ? ie shouldn't EEXIST just skip the chown,
with a special case for the last path component ?
Something along the lines of the following patch (diff to CVS version)
...
- William
--- install.c.orig 2004-01-23 10:26:24.000000000 -0500
+++ install.c 2004-01-23 10:40:27.000000000 -0500
@@ -73,19 +73,31 @@
for (argv += optind; *argv; argv++) {
char *old_argv_ptr = *argv + 1;
char *argv_ptr;
+ unsigned char do_chown;
do {
argv_ptr = strchr(old_argv_ptr, '/');
old_argv_ptr = argv_ptr;
if (argv_ptr) {
*argv_ptr = '\0';
old_argv_ptr++;
+ do_chown = 0; /* don't chown
directories
+ unless it is
the last component
+ in the path */
+ } else {
+ /* always chown the last
component in the path */
+ do_chown = 1;
}
- if ((mkdir(*argv, mode) == -1) &&
(errno != EEXIST)) {
- bb_perror_msg("coulnt create
%s", *argv);
- ret = EXIT_FAILURE;
- break;
+ if (mkdir(*argv, mode) == -1) {
+ if (errno != EEXIST) {
+ bb_perror_msg("coulnt
create %s", *argv);
+ ret = EXIT_FAILURE;
+ break;
+ }
+ } else {
+ /* directory was created, we'll
chown it */
+ do_chown = 1;
}
- else if (lchown(*argv, uid, gid) == -1)
{
+ if (do_chown && (lchown(*argv, uid,
gid) == -1)) {
bb_perror_msg("cannot change
ownership of %s", *argv);
ret = EXIT_FAILURE;
break;
More information about the busybox
mailing list