From owner-svn-src-all@FreeBSD.ORG Tue Jul 1 22:46:39 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BA413EA2; Tue, 1 Jul 2014 22:46:39 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A7B4A285F; Tue, 1 Jul 2014 22:46:39 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s61Mkdbp049308; Tue, 1 Jul 2014 22:46:39 GMT (envelope-from delphij@svn.freebsd.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s61MkdQc049307; Tue, 1 Jul 2014 22:46:39 GMT (envelope-from delphij@svn.freebsd.org) Message-Id: <201407012246.s61MkdQc049307@svn.freebsd.org> From: Xin LI Date: Tue, 1 Jul 2014 22:46:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r268129 - head/bin/mv X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Jul 2014 22:46:39 -0000 Author: delphij Date: Tue Jul 1 22:46:39 2014 New Revision: 268129 URL: http://svnweb.freebsd.org/changeset/base/268129 Log: Check if fchflags() is needed by fstat'ing before and check the results. Reviewed by: jilles X-MFC-With: r267977 Modified: head/bin/mv/mv.c Modified: head/bin/mv/mv.c ============================================================================== --- head/bin/mv/mv.c Tue Jul 1 22:42:53 2014 (r268128) +++ head/bin/mv/mv.c Tue Jul 1 22:46:39 2014 (r268129) @@ -278,6 +278,7 @@ fastcopy(const char *from, const char *t static char *bp = NULL; mode_t oldmode; int nread, from_fd, to_fd; + struct stat tsb; if ((from_fd = open(from, O_RDONLY, 0)) < 0) { warn("fastcopy: open() failed (from): %s", from); @@ -336,10 +337,18 @@ err: if (unlink(to)) * if the server supports flags and we were trying to *remove* flags * on a file that we copied, i.e., that we didn't create.) */ - errno = 0; - if (fchflags(to_fd, sbp->st_flags | UF_ARCHIVE)) - if (errno != EOPNOTSUPP || ((sbp->st_flags & ~UF_ARCHIVE) != 0)) - warn("%s: set flags (was: 0%07o)", to, sbp->st_flags); + if (fstat(to_fd, &tsb) == 0) { + if ((sbp->st_flags & ~UF_ARCHIVE) != + (tsb.st_flags & ~UF_ARCHIVE)) { + if (fchflags(to_fd, + sbp->st_flags | (tsb.st_flags & UF_ARCHIVE))) + if (errno != EOPNOTSUPP || + ((sbp->st_flags & ~UF_ARCHIVE) != 0)) + warn("%s: set flags (was: 0%07o)", + to, sbp->st_flags); + } + } else + warn("%s: cannot stat", to); tval[0].tv_sec = sbp->st_atime; tval[1].tv_sec = sbp->st_mtime;