Print this page
3619 cp -p clobbers permissions/ownership following symbolic links
*** 18,27 ****
--- 18,31 ----
*
* CDDL HEADER END
*/
/*
+ * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
+ */
+
+ /*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
*** 1346,1356 ****
int rc;
times[0] = ss.st_atim;
times[1] = ss.st_mtim;
! rc = utimensat(AT_FDCWD, to, times, 0);
#ifdef XPG4
if ((pflg || mve) && rc != 0) {
(void) fprintf(stderr,
gettext("%s: cannot set times for %s: "), cmd, to);
perror("");
--- 1350,1361 ----
int rc;
times[0] = ss.st_atim;
times[1] = ss.st_mtim;
! rc = utimensat(AT_FDCWD, to, times,
! ISLNK(s1) ? AT_SYMLINK_NOFOLLOW : 0);
#ifdef XPG4
if ((pflg || mve) && rc != 0) {
(void) fprintf(stderr,
gettext("%s: cannot set times for %s: "), cmd, to);
perror("");
*** 1381,1391 ****
--- 1386,1401 ----
*/
static int
chg_mode(char *target, uid_t uid, gid_t gid, mode_t mode)
{
int clearflg = 0; /* controls message printed upon chown() error */
+ struct stat st;
+ /* Don't change mode if target is symlink */
+ if (lstat(target, &st) == 0 && ISLNK(st))
+ return (0);
+
if (chown(target, uid, gid) != 0) {
#ifdef XPG4
if (mve) {
(void) fprintf(stderr, gettext("%s: cannot change"
" owner and group of %s: "), cmd, target);