Skip to content

Commit 0615587

Browse files
committed
unzip: fix multi-platform handling of stat mtime
1 parent 96b689a commit 0615587

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

unzip/bsdunzip.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,10 +635,27 @@ extract_file(struct archive *a, struct archive_entry *e, char **path)
635635
if (lstat(*path, &sb) == 0) {
636636
if (u_opt || f_opt) {
637637
/* check if up-to-date */
638-
if (S_ISREG(sb.st_mode) &&
639-
(sb.st_mtim.tv_sec > mtime.tv_sec ||
638+
if (S_ISREG(sb.st_mode) && (
639+
#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
640+
sb.st_mtimespec.tv_sec > mtime.tv_sec ||
641+
(sb.st_mtimespec.tv_sec == mtime.tv_sec &&
642+
sb.st_mtimespec.tv_nsec >= mtime.tv_nsec)
643+
#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
644+
sb.st_mtim.tv_sec > mtime.tv_sec ||
640645
(sb.st_mtim.tv_sec == mtime.tv_sec &&
641-
sb.st_mtim.tv_nsec >= mtime.tv_nsec)))
646+
sb.st_mtim.tv_nsec >= mtime.tv_nsec)
647+
#elif HAVE_STRUCT_STAT_ST_MTIME_N
648+
sb.st_mtime > mtime.tv_sec ||
649+
(sb.st_mtime == mtime.tv_sec &&
650+
sb.st_mtime_n => mtime.tv_nsec)
651+
#elif HAVE_STRUCT_STAT_ST_MTIME_USEC
652+
sb.st_mtime > mtime.tv_sec ||
653+
(sb.st_mtime == mtime.tv_sec &&
654+
sb.st_mtime_usec * 1000 => mtime.tv_nsec)
655+
#else
656+
sb.st_mtime > mtime.tv_sec
657+
#endif
658+
))
642659
return;
643660
(void)unlink(*path);
644661
} else if (o_opt) {

0 commit comments

Comments
 (0)