Fix -b failure not restoring flags on the destination file.

MFC after:	1 week
Sponsored by:	EMC / Isilon Storage Division
This commit is contained in:
bdrewery 2016-08-10 18:19:11 +00:00
parent 9c0059d165
commit b9f84f5fbf

View File

@ -904,6 +904,8 @@ install(const char *from_name, const char *to_name, u_long fset, u_int flags)
(void)printf("install: %s -> %s\n", to_name, backup);
if (unlink(backup) < 0 && errno != ENOENT) {
serrno = errno;
if (to_sb.st_flags & NOCHANGEBITS)
(void)chflags(to_name, to_sb.st_flags);
unlink(tempfile);
errno = serrno;
err(EX_OSERR, "unlink: %s", backup);
@ -911,6 +913,8 @@ install(const char *from_name, const char *to_name, u_long fset, u_int flags)
if (link(to_name, backup) < 0) {
serrno = errno;
unlink(tempfile);
if (to_sb.st_flags & NOCHANGEBITS)
(void)chflags(to_name, to_sb.st_flags);
errno = serrno;
err(EX_OSERR, "link: %s to %s", to_name,
backup);
@ -1133,16 +1137,26 @@ create_newfile(const char *path, int target, struct stat *sbp)
if (dobackup) {
if ((size_t)snprintf(backup, MAXPATHLEN, "%s%s",
path, suffix) != strlen(path) + strlen(suffix))
path, suffix) != strlen(path) + strlen(suffix)) {
saved_errno = errno;
if (sbp->st_flags & NOCHANGEBITS)
(void)chflags(path, sbp->st_flags);
errno = saved_errno;
errx(EX_OSERR, "%s: backup filename too long",
path);
}
(void)snprintf(backup, MAXPATHLEN, "%s%s",
path, suffix);
if (verbose)
(void)printf("install: %s -> %s\n",
path, backup);
if (rename(path, backup) < 0)
if (rename(path, backup) < 0) {
saved_errno = errno;
if (sbp->st_flags & NOCHANGEBITS)
(void)chflags(path, sbp->st_flags);
errno = saved_errno;
err(EX_OSERR, "rename: %s to %s", path, backup);
}
} else
if (unlink(path) < 0)
saved_errno = errno;