Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method _update_zip_extra_attrs optimization #5753

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions avocado/utils/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ def _update_zip_extra_attrs(self, dst_dir):
return
attr = info.external_attr >> 16
if attr & stat.S_IFLNK == stat.S_IFLNK:
dst = os.path.join(dst_dir, path)
if not os.path.islink(dst):
# Link created as an ordinary file containing the dst path
with open(dst, "r") as dst_path: # pylint: disable=W1514
Expand All @@ -289,12 +288,19 @@ def _update_zip_extra_attrs(self, dst_dir):
# Link is already there and could be outdated. Let's read
# the original destination from the zip file.
src = self._engine.read(path)
os.remove(dst)
os.symlink(src, dst)
try:
os.remove(dst)
os.symlink(src, dst)
except Exception as e:
LOG.warning(f"Failed to update symlink '{dst}': {str(e)}")
continue
continue # Don't override any other attributes on links
mode = attr & 511 # Mask only permissions
if mode and mode != 436: # If mode is stored and is not default
os.chmod(dst, mode)
try:
os.chmod(dst, mode)
except Exception as e:
LOG.warning(f"Failed to update permissions for '{dst}': {str(e)}")

def close(self):
"""
Expand Down