Skip to content

Commit

Permalink
Merge pull request #1 from bentonj-vmw/topic/grossag/zstd3
Browse files Browse the repository at this point in the history
  • Loading branch information
grossag authored Oct 16, 2023
2 parents a33394d + 3622c1c commit 7d586bc
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions conan/tools/files/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ def print_progress(the_size, uncomp_size):
def print_progress(_, __):
pass

def is_symlink_zipinfo(zi):
return (zi.external_attr >> 28) == 0xA

with zipfile.ZipFile(filename, "r") as z:
zip_info = z.infolist()
if pattern:
Expand All @@ -328,27 +331,34 @@ def print_progress(_, __):
extracted_size = 0

print_progress.last_size = -1
if platform.system() == "Windows":
for file_ in zip_info:
extracted_size += file_.file_size
print_progress(extracted_size, uncompress_size)
try:
z.extract(file_, full_path)
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
for file_ in zip_info:
extracted_size += file_.file_size
print_progress(extracted_size, uncompress_size)
try:
keep_permissions = (keep_permissions and platform.system() == "Windows")
for file_ in zip_info:
extracted_size += file_.file_size
print_progress(extracted_size, uncompress_size)
try:
if not is_symlink_zipinfo(file_):
z.extract(file_, full_path)
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)
except Exception as e:
output.error("Error extract %s\n%s" % (file_.filename, str(e)))
else:
# Read extracted file contents to find target path to link to
z.extract(file_, full_path)
full_name = os.path.join(full_path, file_.filename)
target = load(conanfile, full_name)
os.unlink(full_name)
try:
# Try create a link to target path
os.symlink(target, full_name)
except OSError:
# If we failed to create a symlink, just copy the file.
if not os.path.isabs(target):
target = os.path.join(full_path, target)
shutil.copy2(target, full_name)
except Exception as e:
output.error("Error extract %s\n%s" % (file_.filename, str(e)))
output.writeln("")


Expand Down

0 comments on commit 7d586bc

Please sign in to comment.