From 4997dd7f290edf16eeed9e27f2cfa6f5c096213f 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 (#15268) --- 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 73f0d6d82b2..660e82da9fe 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(f"Error extract {file_.filename}\n{str(e)}", error_type="exception") 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(f"Error extract {file_.filename}\n{str(e)}", error_type="exception") + for file_path, ts in file_timestamps: + os.utime(file_path, (ts, ts)) output.writeln("")