Skip to content

Commit

Permalink
Only restore executable permissions on extracted files (#1655)
Browse files Browse the repository at this point in the history
We need to check that the create_system is unix, otherwise the
external_attr does not contain unix permissions. It also doesn't make
much sense to restore any flags other than executable.
  • Loading branch information
BenjaminSchaaf authored Oct 10, 2023
1 parent 2103de4 commit 6a20b01
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions package_control/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from concurrent import futures
from io import BytesIO
from stat import S_IXUSR
from threading import RLock
from urllib.parse import urlencode

Expand Down Expand Up @@ -54,6 +55,8 @@
'https://sublime.wbond.net/repositories.json'
])

ZIP_UNIX_SYSTEM = 3


class PackageManager:

Expand Down Expand Up @@ -1053,8 +1056,10 @@ def _extract_zip(self, name, zf, src_dir, dest_dir, extracted_files=None):
with zf.open(info) as fsrc, open(dest, 'wb') as fdst:
shutil.copyfileobj(fsrc, fdst)

# restore file mode
os.chmod(dest, info.external_attr >> 16)
# Restore executable permissions
if (info.create_system == ZIP_UNIX_SYSTEM
and (info.external_attr >> 16) & S_IXUSR):
os.chmod(dest, os.stat(dest).st_mode | S_IXUSR)

except OSError as e:
if e.errno == 5 or e.errno == 13: # permission denied
Expand Down

0 comments on commit 6a20b01

Please sign in to comment.