Skip to content

Commit 94da117

Browse files
navsudmeta-codesync[bot]
authored andcommitted
Fix execute permissions for flatc binary extracted from PAR files (#18738)
Summary: Pull Request resolved: #18738 When binaries are extracted from PAR files via `importlib.resources.as_file()`, execute permissions are not preserved, causing PermissionError when trying to run them. This change ensures the flatc binary has execute permissions after extraction. Files fixed: - `executorch/exir/_serialize/_flatbuffer.py`: `_run_flatc` - ensure flatc binary has execute permissions Differential Revision: D99780508
1 parent fcccda3 commit 94da117

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

exir/_serialize/_flatbuffer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,14 @@ def _run_flatc(args: Sequence[str]) -> None:
252252
if flatc_resource.is_file():
253253
# Use the provided flatc binary.
254254
with importlib.resources.as_file(flatc_resource) as flatc_path:
255+
# Ensure the binary has execute permissions (needed for PAR files)
256+
import stat
257+
258+
current_mode = flatc_path.stat().st_mode
259+
if not (current_mode & stat.S_IXUSR):
260+
flatc_path.chmod(
261+
current_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
262+
)
255263
subprocess.run([flatc_path] + list(args), check=True)
256264
else:
257265
# Expect the `flatc` tool to be on the system path or set as an env var.

0 commit comments

Comments
 (0)