From 4ed0b8626be8047d1eefab79641a1f199c39edf3 Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Tue, 16 Aug 2022 03:39:29 +0200 Subject: [PATCH] add exec.file.symlink() and use in BuildChroot --- chroot/build.py | 6 +++--- exec/file.py | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/chroot/build.py b/chroot/build.py index 4efa283..4efe0ab 100644 --- a/chroot/build.py +++ b/chroot/build.py @@ -8,7 +8,7 @@ from config import config from constants import Arch, GCC_HOSTSPECS, CROSSDIRECT_PKGS, CHROOT_PATHS from distro.distro import get_kupfer_local from exec.cmd import run_root_cmd -from exec.file import makedir, remove_file, root_makedir, root_write_file +from exec.file import makedir, remove_file, root_makedir, root_write_file, symlink from .abstract import Chroot, get_chroot from .helpers import build_chroot_name @@ -104,11 +104,11 @@ class BuildChroot(Chroot): for target, source in {cc_path: gcc, target_lib_dir: 'lib', target_include_dir: 'usr/include'}.items(): if not os.path.exists(target): logging.debug(f'Symlinking {source} at {target}') - os.symlink(source, target) + symlink(source, target) ld_so = os.path.basename(glob(f"{os.path.join(native_chroot.path, 'usr', 'lib', 'ld-linux-')}*")[0]) ld_so_target = os.path.join(target_lib_dir, ld_so) if not os.path.islink(ld_so_target): - os.symlink(os.path.join('/native', 'usr', 'lib', ld_so), ld_so_target) + symlink(os.path.join('/native', 'usr', 'lib', ld_so), ld_so_target) else: logging.debug(f'ld-linux.so symlink already exists, skipping for {self.name}') diff --git a/exec/file.py b/exec/file.py index 594fe56..0b97284 100644 --- a/exec/file.py +++ b/exec/file.py @@ -135,3 +135,10 @@ def makedir(path, user: Optional[str] = None, group: Optional[str] = None, paren def root_makedir(path, parents: bool = True): return makedir(path, user='root', group='root', parents=parents) + + +def symlink(source, target): + try: + os.symlink(source, target) + except: + run_root_cmd(['ln', '-s', source, target])