From owner-freebsd-bugs Thu Feb 15 11:10: 9 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 7442F37B503 for ; Thu, 15 Feb 2001 11:10:02 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f1FJA2b59324; Thu, 15 Feb 2001 11:10:02 -0800 (PST) (envelope-from gnats) Date: Thu, 15 Feb 2001 11:10:02 -0800 (PST) Message-Id: <200102151910.f1FJA2b59324@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Martin Kammerhofer Subject: Re: bin/25017: cp -pRP does not preserve symlink ownership Reply-To: Martin Kammerhofer Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/25017; it has been noted by GNATS. From: Martin Kammerhofer To: Bruce Evans Cc: mkamm@gmx.net, FreeBSD-gnats-submit@FreeBSD.ORG Subject: Re: bin/25017: cp -pRP does not preserve symlink ownership Date: Thu, 15 Feb 2001 14:25:04 +0100 (CET) Am 12.02.01 hat Bruce Evans folgendes geschrieben: : : This should use a slightly modified version of setfile() (replace : `chown(...)' by `(S_ISLINK(...) ? chown : lchown)(...)', etc. This : will also fix the non-preservation of modes and times for symlinks. : : Bruce : Below is a revised patch following this proposition: Index: utils.c =================================================================== RCS file: /home/ncvs/src/bin/cp/utils.c,v retrieving revision 1.28 diff -u -r1.28 utils.c --- utils.c 2000/10/10 01:48:18 1.28 +++ utils.c 2001/02/15 14:15:03 @@ -224,7 +224,7 @@ warn("symlink: %s", link); return (1); } - return (0); + return (pflag ? setfile(p->fts_statp, 0) : 0); } int @@ -267,20 +267,21 @@ { static struct timeval tv[2]; struct stat ts; - int rval; - int gotstat; + int rval, gotstat, islink; rval = 0; + islink = !fd && S_ISLNK(fs->st_mode); fs->st_mode &= S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO; TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec); TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec); - if (utimes(to.p_path, tv)) { + if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) { warn("utimes: %s", to.p_path); rval = 1; } - if (fd ? fstat(fd, &ts) : stat(to.p_path, &ts)) + if (fd ? fstat(fd, &ts) : + (islink ? lstat(to.p_path, &ts) : stat(to.p_path, &ts))) gotstat = 0; else { gotstat = 1; @@ -295,7 +296,8 @@ */ if (!gotstat || fs->st_uid != ts.st_uid || fs->st_gid != ts.st_gid) if (fd ? fchown(fd, fs->st_uid, fs->st_gid) : - chown(to.p_path, fs->st_uid, fs->st_gid)) { + (islink ? lchown(to.p_path, fs->st_uid, fs->st_gid) : + chown(to.p_path, fs->st_uid, fs->st_gid))) { if (errno != EPERM) { warn("chown: %s", to.p_path); rval = 1; @@ -304,14 +306,17 @@ } if (!gotstat || fs->st_mode != ts.st_mode) - if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode)) { - warn("chown: %s", to.p_path); + if (fd ? fchmod(fd, fs->st_mode) : + (islink ? lchmod(to.p_path, fs->st_mode) + : chmod(to.p_path, fs->st_mode))) { + warn("chmod: %s", to.p_path); rval = 1; } if (!gotstat || fs->st_flags != ts.st_flags) - if (fd ? - fchflags(fd, fs->st_flags) : chflags(to.p_path, fs->st_flags)) { + if (fd ? fchflags(fd, fs->st_flags) : + (islink ? (errno = ENOSYS) + : chflags(to.p_path, fs->st_flags))) { warn("chflags: %s", to.p_path); rval = 1; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message