changeset 13994:29315ace9c5b

3619 cp -p clobbers permissions/ownership following symbolic links Reviewed by: Garrett D'Amore <garrett@damore.org> Reviewed by: Richard Lowe <richlowe@richlowe.net> Approved by: Gordon Ross <gwr@nexenta.com>
author Alexander Eremin <a.eremin@nexenta.com>
date Thu, 28 Mar 2013 00:04:59 +0400
parents 6d652ac77401
children e0554f834eb0
files usr/src/cmd/mv/mv.c
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/mv/mv.c	Thu Mar 28 12:20:55 2013 -0400
+++ b/usr/src/cmd/mv/mv.c	Thu Mar 28 00:04:59 2013 +0400
@@ -20,6 +20,10 @@
  */
 
 /*
+ * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
+ */
+
+/*
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
@@ -1348,7 +1352,8 @@
 	times[0] = ss.st_atim;
 	times[1] = ss.st_mtim;
 
-	rc = utimensat(AT_FDCWD, to, times, 0);
+	rc = utimensat(AT_FDCWD, to, times,
+	    ISLNK(s1) ? AT_SYMLINK_NOFOLLOW : 0);
 #ifdef XPG4
 	if ((pflg || mve) && rc != 0) {
 		(void) fprintf(stderr,
@@ -1383,6 +1388,11 @@
 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