From 10d07de2383ba317d38592e078f13c4439a80a9d Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Tue, 12 Sep 2023 00:27:29 -0400 Subject: [PATCH] Catch `NotADirectoryError` (#13089) --- conda/cli/find_commands.py | 5 +++-- news/13062-find-commands-permission-error | 2 +- tests/cli/test_find_commands.py | 9 +++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/conda/cli/find_commands.py b/conda/cli/find_commands.py index 2276df8507f..af3586f22b3 100644 --- a/conda/cli/find_commands.py +++ b/conda/cli/find_commands.py @@ -72,8 +72,9 @@ def find_commands(include_others=True): m = pat.match(entry.name) if m and entry.is_file(): res.add(m.group(1)) - except (FileNotFoundError, PermissionError): - # FileNotFoundError: directory doesn't exist + except (FileNotFoundError, NotADirectoryError, PermissionError): + # FileNotFoundError: path doesn't exist + # NotADirectoryError: path is not a directory # PermissionError: user doesn't have read access continue return tuple(sorted(res)) diff --git a/news/13062-find-commands-permission-error b/news/13062-find-commands-permission-error index f474d9e2c68..349ec87aa77 100644 --- a/news/13062-find-commands-permission-error +++ b/news/13062-find-commands-permission-error @@ -4,7 +4,7 @@ ### Bug fixes -* Catch `PermissionError` raised by `conda.cli.find_commands.find_commands` when user's `$PATH` contains restricted paths. (#13062) +* Catch `PermissionError` raised by `conda.cli.find_commands.find_commands` when user's `$PATH` contains restricted paths. (#13062, #13089) ### Deprecations diff --git a/tests/cli/test_find_commands.py b/tests/cli/test_find_commands.py index b4a30212926..df7029c41b4 100644 --- a/tests/cli/test_find_commands.py +++ b/tests/cli/test_find_commands.py @@ -21,6 +21,15 @@ def faux_path(tmp_path: Path, monkeypatch: MonkeyPatch) -> Path: (permission / "conda-permission.exe").touch() monkeypatch.setenv("PATH", str(permission), prepend=os.pathsep) + # missing directory + missing_dir = tmp_path / "missing-directory" + monkeypatch.setenv("PATH", str(missing_dir), prepend=os.pathsep) + + # not directory + not_dir = tmp_path / "not-directory" + not_dir.touch() + monkeypatch.setenv("PATH", str(not_dir), prepend=os.pathsep) + # bad executables bad = tmp_path / "bad" bad.mkdir(exist_ok=True)