fix symlinking to lib when conflicting file already exists

This commit is contained in:
Nick Sweeting 2024-10-03 03:56:45 -07:00
parent 490e5ba11d
commit 0f37abb657
No known key found for this signature in database
2 changed files with 8 additions and 10 deletions

View file

@ -60,15 +60,12 @@ class BaseBinary(BaseHook, Binary):
if not (binary.abspath and binary.abspath.exists()): if not (binary.abspath and binary.abspath.exists()):
return return
try: bin_dir.mkdir(parents=True, exist_ok=True)
bin_dir.mkdir(parents=True, exist_ok=True) symlink = bin_dir / binary.name
symlink = bin_dir / binary.name symlink.unlink(missing_ok=True)
symlink.unlink(missing_ok=True) symlink.symlink_to(binary.abspath)
symlink.symlink_to(binary.abspath) symlink.chmod(0o777) # make sure its executable by everyone
except Exception as err:
# print('[red]:warning: Failed to symlink binary into ./lib/bin folder[/red]', err)
pass
@validate_call @validate_call
def load(self, **kwargs) -> Self: def load(self, **kwargs) -> Self:
binary = super().load(**kwargs) binary = super().load(**kwargs)

View file

@ -75,7 +75,7 @@ def create_macos_app_symlink(target: Path, shortcut: Path):
# TODO: should we enforce this? is it useful in any other situation? # TODO: should we enforce this? is it useful in any other situation?
# if platform.system().lower() != 'darwin': # if platform.system().lower() != 'darwin':
# raise Exception(...) # raise Exception(...)
shortcut.unlink(missing_ok=True)
shortcut.write_text(f"""#!/usr/bin/env bash\nexec '{target}' "$@"\n""") shortcut.write_text(f"""#!/usr/bin/env bash\nexec '{target}' "$@"\n""")
shortcut.chmod(0o777) # make sure its executable by everyone shortcut.chmod(0o777) # make sure its executable by everyone
@ -226,6 +226,7 @@ class ChromeBinary(BaseBinary):
create_macos_app_symlink(binary.abspath, symlink) create_macos_app_symlink(binary.abspath, symlink)
else: else:
# otherwise on linux we can symlink directly to binary executable # otherwise on linux we can symlink directly to binary executable
symlink.unlink(missing_ok=True)
symlink.symlink_to(binary.abspath) symlink.symlink_to(binary.abspath)
@staticmethod @staticmethod