aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/chmod.c
diff options
context:
space:
mode:
Diffstat (limited to 'toys/posix/chmod.c')
-rw-r--r--toys/posix/chmod.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/toys/posix/chmod.c b/toys/posix/chmod.c
index ac53957c..3645ebc8 100644
--- a/toys/posix/chmod.c
+++ b/toys/posix/chmod.c
@@ -45,14 +45,20 @@ static int do_chmod(struct dirtree *try)
if (!dirtree_notdotdot(try)) return 0;
- mode = string_to_mode(TT.mode, try->st.st_mode);
- if (FLAG(v)) {
- char *s = dirtree_path(try, 0);
-
- printf("chmod '%s' to %s\n", s, TT.mode);
- free(s);
+ if (FLAG(R) && try->parent && S_ISLNK(try->st.st_mode)) {
+ // Ignore symlinks found during recursion. We'll only try to modify
+ // symlinks mentioned directly as arguments. We'll fail, of course,
+ // but that's what you asked for in that case.
+ } else {
+ mode = string_to_mode(TT.mode, try->st.st_mode);
+ if (FLAG(v)) {
+ char *s = dirtree_path(try, 0);
+
+ printf("chmod '%s' to %s\n", s, TT.mode);
+ free(s);
+ }
+ wfchmodat(dirtree_parentfd(try), try->name, mode);
}
- wfchmodat(dirtree_parentfd(try), try->name, mode);
return FLAG(R)*DIRTREE_RECURSE;
}