Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scandir() crash by returning [] when directory is not found (#13083) #13086

Merged
merged 7 commits into from
Jan 8, 2025

Conversation

delta87
Copy link
Contributor

@delta87 delta87 commented Dec 26, 2024

This PR addresses issue #13083 by modifying the scandir function to handle the case where a non-existent directory is provided. Previously, the function did not return a result for such cases, potentially leading to unhandled errors. Now, if the directory does not exist, the function will return an empty list instead.

Changes made:

Updated scandir to catch FileNotFoundError and return an empty list if the directory does not exist.
Updated the function docstring to reflect the new behavior.
Testing:

Also two tests were added.
Closes #13083

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Dec 26, 2024
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @delta87 for the contribution!

@nicoddemus nicoddemus added the backport 8.3.x apply to PRs at any point; backports the changes to the 8.3.x branch label Jan 6, 2025
@nicoddemus nicoddemus enabled auto-merge (squash) January 6, 2025 11:12
@nicoddemus nicoddemus force-pushed the bugFix/scandir-empty-dir branch from bd13b60 to 835d81b Compare January 6, 2025 11:23
@nicoddemus nicoddemus disabled auto-merge January 6, 2025 11:23
@nicoddemus
Copy link
Member

Hmmm the failure is unrelated, will try to investigate this later.

@The-Compiler
Copy link
Member

Hmmm the failure is unrelated, will try to investigate this later.

Once the fix is in and this PR gets rebased, hopefully things are all green again!

@nicoddemus nicoddemus force-pushed the bugFix/scandir-empty-dir branch from 835d81b to 476e31a Compare January 8, 2025 20:27
@nicoddemus nicoddemus enabled auto-merge (squash) January 8, 2025 20:28
@nicoddemus nicoddemus merged commit 3214263 into pytest-dev:main Jan 8, 2025
28 checks passed
Copy link

patchback bot commented Jan 8, 2025

Backport to 8.3.x: 💚 backport PR created

✅ Backport PR branch: patchback/backports/8.3.x/3214263b2f0d17b265c40cf5f87d70357b9a219d/pr-13086

Backported as #13117

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jan 8, 2025
Fixes #13083

---------

Co-authored-by: Bruno Oliveira <[email protected]>
(cherry picked from commit 3214263)
nicoddemus pushed a commit that referenced this pull request Jan 8, 2025
Fixes #13083

---------

Co-authored-by: Bruno Oliveira <[email protected]>
(cherry picked from commit 3214263)

Co-authored-by: delta87 <[email protected]>
@delta87 delta87 deleted the bugFix/scandir-empty-dir branch January 13, 2025 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 8.3.x apply to PRs at any point; backports the changes to the 8.3.x branch bot:chronographer:provided (automation) changelog entry is part of PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race condition: collection error when directory is deleted before scandir() runs
4 participants