Repository navigation
🐛 fix(api): skip unsearchable directories in find_*_file - #703
Merged
Merged
Conversation
find_config_file and the other find_* lookups check each candidate with Path.is_file(). Until Python 3.14 that only swallows ENOENT, ENOTDIR, EBADF and ELOOP, so a directory on the search path that the caller may not enter makes stat() fail with EACCES and the whole lookup raises PermissionError. A root-owned 0700 directory in XDG_CONFIG_DIRS is enough: on 3.11-3.13 find_config_file crashes, on 3.14 it moves on and returns the file from the next directory, because 3.14's Path.is_file delegates to os.path.isfile. Use os.path.isfile directly so every supported Python gets the 3.14 behaviour. The test denies access to the first site directory with a real chmod, so it runs on POSIX as a non-root user; on 3.14+ it passes with or without the fix.
main moved _find_files up next to find_config_file and reworded its suppressions, so the os.path.isfile check now sits in that copy with the reason on the ignore comment.
The runtime fallback test counted files through Path.is_file, which the lookup no longer calls, so it stubs os.path.isfile instead. Add a case that needs no permission bits: a name over the file system limit makes stat fail with ENAMETOOLONG, which Path.is_file re-raised before Python 3.14 just like EACCES. Reword the changelog entry to fit 120 columns.
The entry now reads as what the lookups do, and also mentions that a name too long for the file system counts as not found instead of raising on Python 3.13 and older.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Python 3.13 and older,
find_config_fileand the otherfind_*_fileandfind_*_fileslookups raisePermissionErrorwhen the user cannot enter one of the directories on the search path, instead of moving on to the next one. It takes an unusual setup, such as a site config directory that only root can open, but once that exists every lookup that reaches it fails. On main, as an unprivileged user:_find_files, added in #586, checks each candidate withPath.is_file(). Before Python 3.14 that only ignores a fewstaterrors, such asENOENTandENOTDIR, and re-raises the rest,EACCESincluded. From 3.14 on,Path.is_file()callsos.path.isfile(), which returnsFalseon anyOSError, so the same lookup gives a different answer depending on the interpreter.The lookup now calls
os.path.isfile()directly, so every supported Python skips such a directory the way 3.14 does. A name too long for the file system is the other case I could trigger. In an existing directory it raisedOSErroron 3.11 to 3.13; now it counts as not found, which is what 3.14 already did.The new tests fail on main under Python 3.11 to 3.13 on Linux, and the #687 fallback test now stubs
os.path.isfile, because the lookup no longer goes throughPath.is_file.The find how-to now says that a directory the user cannot search is skipped, next to the existing note that a directory with the file's name is skipped.