Date: Thu, 15 Feb 2001 11:10:02 -0800 (PST) From: Martin Kammerhofer <mkamm@sbox.tu-graz.ac.at> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/25017: cp -pRP does not preserve symlink ownership Message-ID: <200102151910.f1FJA2b59324@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/25017; it has been noted by GNATS.
From: Martin Kammerhofer <mkamm@sbox.tu-graz.ac.at>
To: Bruce Evans <bde@zeta.org.au>
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200102151910.f1FJA2b59324>
