Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Revert "Simplify fallback for systems without utimensat"
Baptiste Daroussin committed 9 years ago
commit f30f7558e105cd1db8755f8007b1d2a17da01829
parent 753f04d
1 file changed +25 -6
modified libpkg/pkg_add.c
@@ -219,20 +219,39 @@ set_attrs(int fd, char *path, mode_t perm, uid_t uid, gid_t gid,
	}
#else
	struct timeval tv[2];
-
	int ffd;
+
	char *saved_cwd[MAXPATHLEN];

	tv[0].tv_sec = ats->tv_sec;
	tv[0].tv_usec = ats->tv_nsec / 1000;
	tv[1].tv_sec = mts->tv_sec;
	tv[1].tv_usec = mts->tv_nsec / 1000;

-
	ffd = openat(fd, RELATIVE_PATH(path), O_RDWR|O_NOFOLLOW);
-
	if (ffd == -1 || futimes(ffd, tv) == -1) {
-
		pkg_emit_error("Fail to set time on %s: %s", path,
-
		    strerror(errno));
+
	memset(saved_cwd, 0, sizeof (saved_cwd));
+

+
	if (getcwd(saved_cwd, sizeof(saved_cwd) - 1) == NULL) {
+
		pkg_emit_error("Fail to call getcwd: %s", strerror(errno));
		return (EPKG_FATAL);
	}
-
	close(ffd);
+

+
	fchdir(fd);
+

+
	if (lutimes(RELATIVE_PATH(path), tv) == -1) {
+

+
		if (errno != ENOSYS) {
+
			pkg_emit_error("Fail to set time on %s: %s", path,
+
					strerror(errno));
+
			return (EPKG_FATAL);
+
		}
+
		else {
+
			/* Fallback to utimes */
+
			if (utimes(RELATIVE_PATH(path), tv) == -1) {
+
				pkg_emit_error("Fail to set time(fallback) on %s: %s", path,
+
						strerror(errno));
+
				return (EPKG_FATAL);
+
			}
+
		}
+
	}
+
	chdir(saved_cwd);
#endif

	if (getenv("INSTALL_AS_USER") == NULL) {