From 7c161f2d78a4ac40e91c48f85d03002802f1c3eb Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 2 Nov 2021 15:36:03 +0530 Subject: [PATCH] Check for actual executable when prepending the path --- kitty/main.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/kitty/main.py b/kitty/main.py index 6f590d572..21e48158f 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -274,10 +274,12 @@ def safe_samefile(a: str, b: str) -> bool: return os.path.abspath(os.path.realpath(a)) == os.path.abspath(os.path.realpath(b)) -def prepend_if_not_symlinked(path: str, paths_serialized: str) -> str: - # prepend a path only if it is not already present, even as a symlink - for q in paths_serialized.split(os.pathsep): - if safe_samefile(q, path): +def prepend_if_not_present(path: str, paths_serialized: str) -> str: + # prepend a path only if path/kitty is not already present, even as a symlink + pq = os.path.join(path, 'kitty') + for candidate in paths_serialized.split(os.pathsep): + q = os.path.join(candidate, 'kitty') + if safe_samefile(q, pq): return paths_serialized return path + os.pathsep + paths_serialized @@ -294,7 +296,7 @@ def ensure_kitty_in_path() -> None: env_path = os.environ.get('PATH', '') correct_kitty = os.path.join(rpath, 'kitty') if not existing or not safe_samefile(existing, correct_kitty): - os.environ['PATH'] = prepend_if_not_symlinked(rpath, env_path) + os.environ['PATH'] = prepend_if_not_present(rpath, env_path) def setup_environment(opts: Options, cli_opts: CLIOptions) -> None: @@ -314,7 +316,7 @@ def setup_environment(opts: Options, cli_opts: CLIOptions) -> None: # if child_path is None it will be inherited from os.environ, # the other values mean the user doesn't want a PATH if child_path not in ('', DELETE_ENV_VAR) and child_path is not None: - env['PATH'] = prepend_if_not_symlinked(os.path.dirname(kitty_path), env['PATH']) + env['PATH'] = prepend_if_not_present(os.path.dirname(kitty_path), env['PATH']) set_default_env(env)