From 67e600b15fd099ba479f8fd6ff7c9479e34ea188 Mon Sep 17 00:00:00 2001 From: pluknet Date: Thu, 4 Jun 2015 19:18:58 +0000 Subject: Change directory permissions in pre-order. In this order, it won't try to recurse into a directory for which it doesn't have permission, before changing that permission. This follows an existing behavior in other BSDs, linux, OS X. Obtained from: NetBSD --- bin/chmod/chmod.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/chmod/chmod.c b/bin/chmod/chmod.c index 9b80157..2ccce2d 100644 --- a/bin/chmod/chmod.c +++ b/bin/chmod/chmod.c @@ -162,14 +162,16 @@ done: argv += optind; atflag = AT_SYMLINK_NOFOLLOW; switch (p->fts_info) { - case FTS_D: /* Change it at FTS_DP. */ + case FTS_D: if (!Rflag) fts_set(ftsp, p, FTS_SKIP); - continue; + break; case FTS_DNR: /* Warn, chmod. */ warnx("%s: %s", p->fts_path, strerror(p->fts_errno)); rval = 1; break; + case FTS_DP: /* Already changed at FTS_D. */ + continue; case FTS_ERR: /* Warn, continue. */ case FTS_NS: warnx("%s: %s", p->fts_path, strerror(p->fts_errno)); -- cgit v1.1