Skip to content

Commit

Permalink
Extract .zip files with recorded file timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
iskunk committed Dec 13, 2023
1 parent c655809 commit 16b797e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion conan/tools/files/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import subprocess
import sys
import time
from contextlib import contextmanager
from fnmatch import fnmatch
from shutil import which
Expand Down Expand Up @@ -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("")


Expand Down

0 comments on commit 16b797e

Please sign in to comment.