Skip to content

Commit

Permalink
Method _update_zip_extra_attrs: Remove excess assignments from dst an…
Browse files Browse the repository at this point in the history
…d handle exceptions in adding files
  • Loading branch information
mataotao committed Aug 25, 2023
1 parent 04b6163 commit c215c1c
Showing 1 changed file with 10 additions and 4 deletions.
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:
warnings.append(f"Failed to update permissions for '{dst}': {str(e)}")

def close(self):
"""
Expand Down

0 comments on commit c215c1c

Please sign in to comment.