Use *at functions with appropriate flags instead of lstat/lchown
This commit is contained in:
17
chown.c
17
chown.c
@@ -1,5 +1,6 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <grp.h>
|
||||
#include <limits.h>
|
||||
#include <pwd.h>
|
||||
@@ -18,19 +19,13 @@ static int ret = 0;
|
||||
static void
|
||||
chownpwgr(const char *path, struct stat *st, void *data, struct recursor *r)
|
||||
{
|
||||
char *chownf_name;
|
||||
int (*chownf)(const char *, uid_t, gid_t);
|
||||
int flags = 0;
|
||||
|
||||
if ((r->maxdepth == 0 && r->follow == 'P') || (r->follow == 'H' && r->depth) || (hflag && !(r->depth))) {
|
||||
chownf_name = "lchown";
|
||||
chownf = lchown;
|
||||
} else {
|
||||
chownf_name = "chown";
|
||||
chownf = chown;
|
||||
}
|
||||
if ((r->maxdepth == 0 && r->follow == 'P') || (r->follow == 'H' && r->depth) || (hflag && !(r->depth)))
|
||||
flags |= AT_SYMLINK_NOFOLLOW;
|
||||
|
||||
if (chownf(path, uid, gid) < 0) {
|
||||
weprintf("%s %s:", chownf_name, path);
|
||||
if (fchownat(AT_FDCWD, path, uid, gid, flags) < 0) {
|
||||
weprintf("chown %s:", path);
|
||||
ret = 1;
|
||||
} else if (S_ISDIR(st->st_mode)) {
|
||||
recurse(path, NULL, r);
|
||||
|
Reference in New Issue
Block a user