From 59f7f8d9fa3fe2940e50a276496a6b1ec3b72f75 Mon Sep 17 00:00:00 2001 From: Marek Fiala Date: Thu, 27 Jul 2023 16:08:52 +0200 Subject: [PATCH] fix(tools): Restore file permissions when extracting zip on unix --- tools/idf_tools.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/idf_tools.py b/tools/idf_tools.py index 2809fdc7aa9b..daa3773df51c 100755 --- a/tools/idf_tools.py +++ b/tools/idf_tools.py @@ -434,6 +434,14 @@ def unpack(filename, destination): # type: (str, str) -> None # https://bugs.python.org/issue17153 destination = str(destination) archive_obj.extractall(destination) + # ZipFile on Unix systems does not preserve file permissions while extracting it + # We need to reset the permissions afterward + if sys.platform != 'win32' and filename.endswith('zip') and isinstance(archive_obj, ZipFile): + for file_info in archive_obj.infolist(): + extracted_file = os.path.join(destination, file_info.filename) + extracted_permissions = file_info.external_attr >> 16 & 0o777 # Extract Unix permissions + if os.path.exists(extracted_file): + os.chmod(extracted_file, extracted_permissions) def splittype(url): # type: (str) -> Tuple[Optional[str], str]