Skip to content

bpo-33635: Handling Bad file descriptor in Path.is_file and related. #8542

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

Merged
merged 2 commits into from
Aug 27, 2018

Conversation

spodym
Copy link
Contributor

@spodym spodym commented Jul 29, 2018

In macOS stat on some file descriptors will result in bad file descriptor OSError. This PR is guarding agains this exception in is_dir, is_file and similar methods. DirEntry.is_dir can also throw this exception so I have extended _RecursiveWildcardSelector._iterate_directories with the same error ignoring pattern.

(default) ➜  cpython git:(fix-issue-33635) ls /dev/fd
0 1 2 3 4
(default) ➜  cpython git:(fix-issue-33635) stat /dev/fd/3
stat: /dev/fd/3: stat: Bad file descriptor
(default) ➜  cpython git:(fix-issue-33635) python
Python 3.6.4 (default, Jan  6 2018, 11:51:59)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib
>>> pathlib.Path('/dev/fd/3').is_file()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 1340, in is_file
    return S_ISREG(self.stat().st_mode)
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 1136, in stat
    return self._accessor.stat(self)
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 387, in wrapped
    return strfunc(str(pathobj), *args)
OSError: [Errno 9] Bad file descriptor: '/dev/fd/3'

https://bugs.python.org/issue33635

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

When your account is ready, please add a comment in this pull request
and a Python core developer will remove the CLA not signed label
to make the bot check again.

You can check yourself
to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@zooba
Copy link
Member

zooba commented Jul 29, 2018

@spodym Just need to add the NEWS item. Click on "Details" next to the failed check for instructions on how to use blurb to add it.

@spodym
Copy link
Contributor Author

spodym commented Aug 1, 2018

@zooba Hi! :) Is there anything more to improve on in this PR?

@zooba
Copy link
Member

zooba commented Aug 27, 2018

@spodym Nope! Sorry for leaving this so long, and thanks for the work!

@zooba zooba merged commit 216b745 into python:master Aug 27, 2018
@miss-islington
Copy link
Contributor

Thanks @spodym for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-8960 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 27, 2018
miss-islington added a commit that referenced this pull request Aug 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants