aboutsummaryrefslogtreecommitdiff
path: root/bin/mv
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2014-07-01 22:46:39 +0000
committerXin LI <delphij@FreeBSD.org>2014-07-01 22:46:39 +0000
commitc15455feb3aa9e3357a8cfc32ed4f3c0880cdab0 (patch)
tree71fd30debbeb3dd6fc6a25056dce59cd0314fba4 /bin/mv
parent30324e945a9ded73d66cff6462fff1664ac0a416 (diff)
downloadsrc-c15455feb3aa9e3357a8cfc32ed4f3c0880cdab0.tar.gz
src-c15455feb3aa9e3357a8cfc32ed4f3c0880cdab0.zip
Check if fchflags() is needed by fstat'ing before and check
the results. Reviewed by: jilles X-MFC-With: r267977
Notes
Notes: svn path=/head/; revision=268129
Diffstat (limited to 'bin/mv')
-rw-r--r--bin/mv/mv.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/bin/mv/mv.c b/bin/mv/mv.c
index ee5264356de6..3e832acbfdf0 100644
--- a/bin/mv/mv.c
+++ b/bin/mv/mv.c
@@ -278,6 +278,7 @@ fastcopy(const char *from, const char *to, struct stat *sbp)
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;