Skip to content

Commit

Permalink
SimpleProject: Teach maybe_strip_elf_file to check for symlinks
Browse files Browse the repository at this point in the history
If a file is a symlink we don't want to actually strip it and lose the
link. Moreover, is_file() can raise a PermissionError for a symlink to a
path we can't access when building on the host (e.g. if you create an
extra-files tree with an absolute symlink to somewhere in /root)
  • Loading branch information
jrtc27 committed Jan 28, 2024
1 parent 201e925 commit af47e1d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pycheribuild/projects/simple_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,10 @@ def __run_process_with_filtered_output(self, proc: subprocess.Popen, logfile: "O
def maybe_strip_elf_file(self, file: Path, *, output_path: "Optional[Path]" = None,
print_verbose_only=True) -> bool:
"""Runs llvm-strip on the file if it is an ELF file and it is safe to do so."""
if not file.is_file():
# NB: Must check if it's a symlink first; if it refers to a path we
# don't have permission to stat on the host (e.g. a symlink into /root)
# then is_file() will raise a PermissionError.
if file.is_symlink() or not file.is_file():
return False
try:
with file.open("rb") as f:
Expand Down

0 comments on commit af47e1d

Please sign in to comment.