logo

utils-std

Collection of commonly available Unix tools
commit: a332cf0349ff942600f34fcef9775fd09b2bb67a
parent bb298210abf592c18230160143f35d70c18958b8
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed,  1 May 2024 03:07:13 +0200

cmd/chown: More straightforward logic for checking changes

Diffstat:

Mcmd/chown.c6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/cmd/chown.c b/cmd/chown.c @@ -129,7 +129,11 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo return 1; } - if(stats.st_uid != user && stats.st_gid != group) + bool change = false; + if(user != (uid_t)-1 && stats.st_uid != user) change = true; + if(group != (uid_t)-1 && stats.st_gid != group) change = true; + + if(change) { assert(errno == 0); if(fchownat(fd, name, user, group, chown_opts) != 0)