commit 05bc9318ddcf558fc22158ed06f5270b4408aeb9 Author: Jacob Welsh AuthorDate: Thu Apr 18 21:03:48 2024 +0000 Commit: Jacob Welsh CommitDate: Thu Apr 18 21:07:23 2024 +0000 busybox/archival: switch from utimes to utimensat, allowing for setting nanoseconds when provided by the format This brings it into agreement with the new code for saving and restoring parent directory timestamps. Using utimes wasn't a good choice there as it could lose resolution. diff --git a/base/busybox/archival/libarchive/data_extract_all.c b/base/busybox/archival/libarchive/data_extract_all.c index 69e69fb..fc5fbc1 100644 --- a/base/busybox/archival/libarchive/data_extract_all.c +++ b/base/busybox/archival/libarchive/data_extract_all.c @@ -211,11 +211,15 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle) chmod(file_header->name, file_header->mode); } if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) { - struct timeval t[2]; + struct timespec t[2]; - t[1].tv_sec = t[0].tv_sec = file_header->mtime; - t[1].tv_usec = t[0].tv_usec = 0; - utimes(file_header->name, t); + /* For portability, it's unclear if we can assume struct timespec has only the two known fields. */ + memset(t, 0, sizeof t); + t[1].tv_sec = file_header->mtime; + t[1].tv_nsec = file_header->mtime_nsec; + /* Setting atime the same as mtime. */ + t[0] = t[1]; + utimensat(AT_FDCWD, file_header->name, t, 0); } } diff --git a/base/busybox/include/bb_archive.h b/base/busybox/include/bb_archive.h index 5d9e24c..f82e2fc 100644 --- a/base/busybox/include/bb_archive.h +++ b/base/busybox/include/bb_archive.h @@ -40,6 +40,7 @@ typedef struct file_header_t { gid_t gid; mode_t mode; time_t mtime; + long mtime_nsec; /* TODO actually use this when supported by the format */ dev_t device; } file_header_t;