From 16b797ef38c6b4e2258d3d4df1f2030e74c0994d Mon Sep 17 00:00:00 2001 From: Daniel Richard G Date: Wed, 13 Dec 2023 12:11:30 -0500 Subject: [PATCH] Extract .zip files with recorded file timestamps --- conan/tools/files/files.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/conan/tools/files/files.py b/conan/tools/files/files.py index b4fda884738..faa64f6e5f1 100644 --- a/conan/tools/files/files.py +++ b/conan/tools/files/files.py @@ -4,6 +4,7 @@ import shutil import subprocess import sys +import time from contextlib import contextmanager from fnmatch import fnmatch from shutil import which @@ -341,18 +342,24 @@ def print_progress(_, __): except Exception as e: output.error("Error extract %s\n%s" % (file_.filename, str(e))) else: # duplicated for, to avoid a platform check for each zipped file + file_timestamps = [] for file_ in zip_info: extracted_size += file_.file_size print_progress(extracted_size, uncompress_size) try: z.extract(file_, full_path) + file_path = os.path.join(full_path, file_.filename) + ts = time.mktime(file_.date_time + (0, 0, -1)) + file_timestamps.append((file_path, ts)) if keep_permissions: # Could be dangerous if the ZIP has been created in a non nix system # https://bugs.python.org/issue15795 perm = file_.external_attr >> 16 & 0xFFF - os.chmod(os.path.join(full_path, file_.filename), perm) + os.chmod(file_path, perm) except Exception as e: output.error("Error extract %s\n%s" % (file_.filename, str(e))) + for file_path, ts in file_timestamps: + os.utime(file_path, (ts, ts)) output.writeln("")