Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -c to chmod, improve message, and switch to FLAG() macros #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions toys/posix/chmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* See http://opengroup.org/onlinepubs/9699919799/utilities/chmod.html

USE_CHMOD(NEWTOY(chmod, "<2?vRf[-vf]", TOYFLAG_BIN))
USE_CHMOD(NEWTOY(chmod, "<2?vRcf[-vf]", TOYFLAG_BIN))

config CHMOD
bool "chmod"
Expand Down Expand Up @@ -46,14 +46,15 @@ static int do_chmod(struct dirtree *try)
if (!dirtree_notdotdot(try)) return 0;

mode = string_to_mode(TT.mode, try->st.st_mode);
if (toys.optflags & FLAG_v) {
if ((FLAG(v) && !FLAG(c)) || (FLAG(c) && try->st.st_mode != mode)) {
char *s = dirtree_path(try, 0);
printf("chmod '%s' to %04o\n", s, mode);
printf("chmod '%s' from %04o to %04o\n",
s, try->st.st_mode&~S_IFMT, mode&~S_IFMT);
free(s);
}
wfchmodat(dirtree_parentfd(try), try->name, mode);

return (toys.optflags & FLAG_R) ? DIRTREE_RECURSE : 0;
return FLAG(R) ? DIRTREE_RECURSE : 0;
}

void chmod_main(void)
Expand Down