From 6a20b0106ba20a4e63d794865dbd1e6cf469cfa7 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 10 Oct 2023 19:40:10 +1100 Subject: [PATCH] Only restore executable permissions on extracted files (#1655) 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. --- package_control/package_manager.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/package_control/package_manager.py b/package_control/package_manager.py index 9c68a405..51b3c2c7 100644 --- a/package_control/package_manager.py +++ b/package_control/package_manager.py @@ -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 @@ -54,6 +55,8 @@ 'https://sublime.wbond.net/repositories.json' ]) +ZIP_UNIX_SYSTEM = 3 + class PackageManager: @@ -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