diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-27 16:07:20 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-27 16:07:20 +0000 |
commit | 51b4c92f80dc232b9d34985f99a4479393644433 (patch) | |
tree | e62b6e2b809db8135d640e3b8222cfd4d52d9098 /coreutils/chmod.c | |
parent | fefb279ace2da131cad369a3cc6983a1bc220a4a (diff) | |
download | busybox-w32-51b4c92f80dc232b9d34985f99a4479393644433.tar.gz busybox-w32-51b4c92f80dc232b9d34985f99a4479393644433.tar.bz2 busybox-w32-51b4c92f80dc232b9d34985f99a4479393644433.zip |
chown: add -vcf support if CONFIG_DESKTOP
chmod: stop following symlinks
Diffstat (limited to 'coreutils/chmod.c')
-rw-r--r-- | coreutils/chmod.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/coreutils/chmod.c b/coreutils/chmod.c index 18334b8bb..c4f8fa0b2 100644 --- a/coreutils/chmod.c +++ b/coreutils/chmod.c | |||
@@ -22,9 +22,23 @@ | |||
22 | #define OPT_QUIET (USE_DESKTOP(option_mask32 & 8) SKIP_DESKTOP(0)) | 22 | #define OPT_QUIET (USE_DESKTOP(option_mask32 & 8) SKIP_DESKTOP(0)) |
23 | #define OPT_STR ("-R" USE_DESKTOP("vcf")) | 23 | #define OPT_STR ("-R" USE_DESKTOP("vcf")) |
24 | 24 | ||
25 | /* TODO: | ||
26 | * chmod never changes the permissions of symbolic links; the chmod | ||
27 | * system call cannot change their permissions. This is not a problem | ||
28 | * since the permissions of symbolic links are never used. | ||
29 | * However, for each symbolic link listed on the command line, chmod changes | ||
30 | * the permissions of the pointed-to file. In contrast, chmod ignores | ||
31 | * symbolic links encountered during recursive directory traversals. | ||
32 | */ | ||
33 | |||
25 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | 34 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) |
26 | { | 35 | { |
27 | mode_t newmode = statbuf->st_mode; | 36 | mode_t newmode = statbuf->st_mode; |
37 | |||
38 | // TODO: match GNU behavior: | ||
39 | // if (depth > 0 && S_ISLNK(statbuf->st_mode)) return TRUE; | ||
40 | // if (depth == 0) follow link | ||
41 | |||
28 | if (!bb_parse_mode((char *)junk, &newmode)) | 42 | if (!bb_parse_mode((char *)junk, &newmode)) |
29 | bb_error_msg_and_die("invalid mode: %s", (char *)junk); | 43 | bb_error_msg_and_die("invalid mode: %s", (char *)junk); |
30 | 44 | ||
@@ -33,7 +47,7 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | |||
33 | || (OPT_CHANGED && statbuf->st_mode != newmode) | 47 | || (OPT_CHANGED && statbuf->st_mode != newmode) |
34 | ) { | 48 | ) { |
35 | printf("mode of '%s' changed to %04o (%s)\n", fileName, | 49 | printf("mode of '%s' changed to %04o (%s)\n", fileName, |
36 | newmode & 7777, bb_mode_string(newmode)+1); | 50 | newmode & 07777, bb_mode_string(newmode)+1); |
37 | } | 51 | } |
38 | return TRUE; | 52 | return TRUE; |
39 | } | 53 | } |
@@ -48,10 +62,11 @@ int chmod_main(int argc, char **argv) | |||
48 | char *arg, **argp; | 62 | char *arg, **argp; |
49 | char *smode; | 63 | char *smode; |
50 | 64 | ||
51 | /* Convert first encountered -r into a-r, etc */ | 65 | /* Convert first encountered -r into a-r, -w into a-w etc */ |
52 | argp = argv + 1; | 66 | argp = argv + 1; |
53 | while ((arg = *argp)) { | 67 | while ((arg = *argp)) { |
54 | /* Protect against mishandling e.g. "chmod 644 -r" */ | 68 | /* Mode spec must be the first arg (sans -R etc) */ |
69 | /* (protect against mishandling e.g. "chmod 644 -r") */ | ||
55 | if (arg[0] != '-') | 70 | if (arg[0] != '-') |
56 | break; | 71 | break; |
57 | /* An option. Not a -- or valid option? */ | 72 | /* An option. Not a -- or valid option? */ |
@@ -72,8 +87,14 @@ int chmod_main(int argc, char **argv) | |||
72 | 87 | ||
73 | /* Ok, ready to do the deed now */ | 88 | /* Ok, ready to do the deed now */ |
74 | do { | 89 | do { |
75 | if (!recursive_action(*argv, OPT_RECURSE, TRUE, FALSE, | 90 | if (!recursive_action(*argv, |
76 | fileAction, fileAction, smode)) { | 91 | OPT_RECURSE, // recurse |
92 | FALSE, // follow links: GNU doesn't | ||
93 | FALSE, // depth first | ||
94 | fileAction, // file action | ||
95 | fileAction, // dir action | ||
96 | smode) // user data | ||
97 | ) { | ||
77 | retval = EXIT_FAILURE; | 98 | retval = EXIT_FAILURE; |
78 | } | 99 | } |
79 | } while (*++argv); | 100 | } while (*++argv); |