1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-17 15:27:36 +00:00

- Properly set mode and atime/ctime for symlinks

Approved by:	des
This commit is contained in:
Alex Kozlov 2015-12-13 21:31:45 +00:00
parent 371028a3b7
commit 46021e0128
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=292172

View File

@ -127,7 +127,6 @@ errorx(const char *fmt, ...)
exit(1); exit(1);
} }
#if 0
/* non-fatal error message + errno */ /* non-fatal error message + errno */
static void static void
warning(const char *fmt, ...) warning(const char *fmt, ...)
@ -143,7 +142,6 @@ warning(const char *fmt, ...)
va_end(ap); va_end(ap);
fprintf(stderr, ": %s\n", strerror(errno)); fprintf(stderr, ": %s\n", strerror(errno));
} }
#endif
/* non-fatal error message, no errno */ /* non-fatal error message, no errno */
static void static void
@ -539,12 +537,21 @@ extract_file(struct archive *a, struct archive_entry *e, char **path)
return; return;
} }
ts[0].tv_sec = 0;
ts[0].tv_nsec = UTIME_NOW;
ts[1] = mtime;
/* process symlinks */ /* process symlinks */
linkname = archive_entry_symlink(e); linkname = archive_entry_symlink(e);
if (linkname != NULL) { if (linkname != NULL) {
if (symlink(linkname, *path) < 0) if (symlink(linkname, *path) != 0)
error("symlink('%s')", *path); error("symlink('%s')", *path);
info(" extracting: %s -> %s\n", *path, linkname); info(" extracting: %s -> %s\n", *path, linkname);
if (lchmod(*path, mode) != 0)
warning("Cannot set mode for '%s'", *path);
/* set access and modification time */
if (utimensat(AT_FDCWD, *path, ts, AT_SYMLINK_NOFOLLOW) != 0)
warning("utimensat('%s')", *path);
return; return;
} }
@ -629,9 +636,6 @@ extract_file(struct archive *a, struct archive_entry *e, char **path)
info("\n"); info("\n");
/* set access and modification time */ /* set access and modification time */
ts[0].tv_sec = 0;
ts[0].tv_nsec = UTIME_NOW;
ts[1] = mtime;
if (futimens(fd, ts) != 0) if (futimens(fd, ts) != 0)
error("futimens('%s')", *path); error("futimens('%s')", *path);
if (close(fd) != 0) if (close(fd) != 0)