Skip to content

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

Merged
zooba merged 2 commits into
python:masterfrom
spodym:fix-issue-33635
Aug 27, 2018
Merged

bpo-33635: Handling Bad file descriptor in Path.is_file and related.#8542
zooba merged 2 commits into
python:masterfrom
spodym:fix-issue-33635

Conversation

@spodym

@spodym spodym commented Jul 29, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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

zooba commented Jul 29, 2018

Copy link
Copy Markdown
Member

@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

spodym commented Aug 1, 2018

Copy link
Copy Markdown
Contributor Author

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

@zooba

zooba commented Aug 27, 2018

Copy link
Copy Markdown
Member

@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
Copy Markdown
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
Copy Markdown

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
…ythonGH-8542)

(cherry picked from commit 216b745)

Co-authored-by: Przemysław Spodymek <przemyslaw@spodymek.com>
miss-islington added a commit that referenced this pull request Aug 27, 2018
…H-8542)

(cherry picked from commit 216b745)

Co-authored-by: Przemysław Spodymek <przemyslaw@spodymek.com>
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