import os import sys def fix_links(root_dir): root_dir = os.path.abspath(root_dir) for root, dirs, files in os.walk(root_dir): for name in files + dirs: path = os.path.join(root, name) if os.path.islink(path): target = os.readlink(path) if target.startswith('/'): # Calculate the relative path from the current folder back to the sysroot relative_to_sysroot = os.path.relpath(root_dir, root) new_target = os.path.normpath(os.path.join(relative_to_sysroot, target.lstrip('/'))) print(f"Fixing: {path} -> {new_target}") os.unlink(path) os.symlink(new_target, path) if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python3 fix_links.py ") else: fix_links(sys.argv[1])