chown: add -vcf support if CONFIG_DESKTOP

chmod: stop following symlinks
This commit is contained in:
Denis Vlasenko
2006-10-27 16:07:20 +00:00
parent fefb279ace
commit 51b4c92f80
3 changed files with 71 additions and 27 deletions

View File

@ -22,9 +22,23 @@
#define OPT_QUIET (USE_DESKTOP(option_mask32 & 8) SKIP_DESKTOP(0))
#define OPT_STR ("-R" USE_DESKTOP("vcf"))
/* TODO:
* chmod never changes the permissions of symbolic links; the chmod
* system call cannot change their permissions. This is not a problem
* since the permissions of symbolic links are never used.
* However, for each symbolic link listed on the command line, chmod changes
* the permissions of the pointed-to file. In contrast, chmod ignores
* symbolic links encountered during recursive directory traversals.
*/
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
{
mode_t newmode = statbuf->st_mode;
// TODO: match GNU behavior:
// if (depth > 0 && S_ISLNK(statbuf->st_mode)) return TRUE;
// if (depth == 0) follow link
if (!bb_parse_mode((char *)junk, &newmode))
bb_error_msg_and_die("invalid mode: %s", (char *)junk);
@ -33,7 +47,7 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|| (OPT_CHANGED && statbuf->st_mode != newmode)
) {
printf("mode of '%s' changed to %04o (%s)\n", fileName,
newmode & 7777, bb_mode_string(newmode)+1);
newmode & 07777, bb_mode_string(newmode)+1);
}
return TRUE;
}
@ -48,10 +62,11 @@ int chmod_main(int argc, char **argv)
char *arg, **argp;
char *smode;
/* Convert first encountered -r into a-r, etc */
/* Convert first encountered -r into a-r, -w into a-w etc */
argp = argv + 1;
while ((arg = *argp)) {
/* Protect against mishandling e.g. "chmod 644 -r" */
/* Mode spec must be the first arg (sans -R etc) */
/* (protect against mishandling e.g. "chmod 644 -r") */
if (arg[0] != '-')
break;
/* An option. Not a -- or valid option? */
@ -72,8 +87,14 @@ int chmod_main(int argc, char **argv)
/* Ok, ready to do the deed now */
do {
if (!recursive_action(*argv, OPT_RECURSE, TRUE, FALSE,
fileAction, fileAction, smode)) {
if (!recursive_action(*argv,
OPT_RECURSE, // recurse
FALSE, // follow links: GNU doesn't
FALSE, // depth first
fileAction, // file action
fileAction, // dir action
smode) // user data
) {
retval = EXIT_FAILURE;
}
} while (*++argv);