Index: bin/mv/mv.c =================================================================== --- bin/mv/mv.c (revision 267984) +++ bin/mv/mv.c (working copy) @@ -278,6 +278,7 @@ fastcopy(const char *from, const char *to, struct static char *bp = NULL; mode_t oldmode; int nread, from_fd, to_fd; + struct stat to_sb; if ((from_fd = open(from, O_RDONLY, 0)) < 0) { warn("fastcopy: open() failed (from): %s", from); @@ -329,6 +330,7 @@ err: if (unlink(to)) */ preserve_fd_acls(from_fd, to_fd, from, to); (void)close(from_fd); + /* * XXX * NFS doesn't support chflags; ignore errors unless there's reason @@ -336,10 +338,19 @@ 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, &to_sb) == 0) { + if ((sbp->st_flags & ~UF_ARCHIVE) != + (to_sb.st_flags & ~UF_ARCHIVE)) { + errno = 0; + if (fchflags(to_fd, + sbp->st_flags | (to_sb.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: can not stat", to); tval[0].tv_sec = sbp->st_atime; tval[1].tv_sec = sbp->st_mtime;