Check if fchflags() is needed by fstat'ing before and check
the results. Reviewed by: jilles X-MFC-With: r267977
This commit is contained in:
parent
ff95e6ff7f
commit
da50471fef
17
bin/mv/mv.c
17
bin/mv/mv.c
@ -278,6 +278,7 @@ fastcopy(const char *from, const char *to, struct stat *sbp)
|
|||||||
static char *bp = NULL;
|
static char *bp = NULL;
|
||||||
mode_t oldmode;
|
mode_t oldmode;
|
||||||
int nread, from_fd, to_fd;
|
int nread, from_fd, to_fd;
|
||||||
|
struct stat tsb;
|
||||||
|
|
||||||
if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
|
if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
|
||||||
warn("fastcopy: open() failed (from): %s", from);
|
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
|
* 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.)
|
* on a file that we copied, i.e., that we didn't create.)
|
||||||
*/
|
*/
|
||||||
errno = 0;
|
if (fstat(to_fd, &tsb) == 0) {
|
||||||
if (fchflags(to_fd, sbp->st_flags | UF_ARCHIVE))
|
if ((sbp->st_flags & ~UF_ARCHIVE) !=
|
||||||
if (errno != EOPNOTSUPP || ((sbp->st_flags & ~UF_ARCHIVE) != 0))
|
(tsb.st_flags & ~UF_ARCHIVE)) {
|
||||||
warn("%s: set flags (was: 0%07o)", to, sbp->st_flags);
|
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[0].tv_sec = sbp->st_atime;
|
||||||
tval[1].tv_sec = sbp->st_mtime;
|
tval[1].tv_sec = sbp->st_mtime;
|
||||||
|
Loading…
Reference in New Issue
Block a user