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

pathlib: Path.exists broken #66948

Closed
hvenev mannequin opened this issue Oct 29, 2014 · 11 comments
Closed

pathlib: Path.exists broken #66948

hvenev mannequin opened this issue Oct 29, 2014 · 11 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@hvenev
Copy link
Mannequin

hvenev mannequin commented Oct 29, 2014

BPO 22759
Nosy @birkenfeld, @pitrou, @hvenev
Files
  • py.patch
  • path_exists_enotdir.patch
  • path_exists_enotdir2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2014-10-30.22:16:28.601>
    created_at = <Date 2014-10-29.15:30:32.611>
    labels = ['type-bug']
    title = 'pathlib: Path.exists broken'
    updated_at = <Date 2014-10-30.22:16:28.599>
    user = 'https://github.com/hvenev'

    bugs.python.org fields:

    activity = <Date 2014-10-30.22:16:28.599>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-10-30.22:16:28.601>
    closer = 'pitrou'
    components = []
    creation = <Date 2014-10-29.15:30:32.611>
    creator = 'h.venev'
    dependencies = []
    files = ['37066', '37078', '37079']
    hgrepos = []
    issue_num = 22759
    keywords = ['patch']
    message_count = 11.0
    messages = ['230214', '230221', '230222', '230225', '230292', '230293', '230294', '230295', '230297', '230303', '230304']
    nosy_count = 4.0
    nosy_names = ['georg.brandl', 'pitrou', 'python-dev', 'h.venev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue22759'
    versions = ['Python 3.4', 'Python 3.5']

    @hvenev
    Copy link
    Mannequin Author

    hvenev mannequin commented Oct 29, 2014

    $ touch a
    c: stat("a/x", ...) -> errno=ENOTDIR
    $ python
    >>> pathlib.Path('a/x').exists()

    This should return False and not throw an exception.

    Patch not tested.

    @hvenev
    Copy link
    Mannequin Author

    hvenev mannequin commented Oct 29, 2014

    Tested and works.

    @pitrou pitrou added the type-bug An unexpected behavior, bug, or error label Oct 29, 2014
    @birkenfeld
    Copy link
    Member

    os.path.exists() ignores *all* OSErrors from stat. This is probably too broad, but only ignoring ENOENT is probably too narrow.

    @hvenev
    Copy link
    Mannequin Author

    hvenev mannequin commented Oct 29, 2014

    ENAMETOOLONG and possibly ELOOP should also return False.
    EACCES, EOVERFLOW and ENOMEM should probably be forwarded.
    EFAULT should not happen.

    @pitrou
    Copy link
    Member

    pitrou commented Oct 30, 2014

    ENAMETOOLONG: that doesn't mean the file doesn't exist. For example, it could be accessed by changing the current directory and shortening the residual path name.

    ELOOP: unfortunately it doesn't guarantee that there is a real symlink loop, just that the OS decided to bail out after a certain number of indirections.

    So in both cases I think we should let the errors bubble up.

    @pitrou
    Copy link
    Member

    pitrou commented Oct 30, 2014

    Here is a patch with tests.

    @hvenev
    Copy link
    Mannequin Author

    hvenev mannequin commented Oct 30, 2014

    Should I file bugs for is_dir, is_file, is_symlink, is_socket, is_fifo, is_block_device and is_char_device?

    @pitrou
    Copy link
    Member

    pitrou commented Oct 30, 2014

    Le 30/10/2014 20:36, Hristo Venev a écrit :

    Hristo Venev added the comment:

    Should I file bugs for is_dir, is_file, is_symlink, is_socket, is_fifo, is_block_device and is_char_device?

    Hmm... good catch. No, this issue will do.

    @pitrou
    Copy link
    Member

    pitrou commented Oct 30, 2014

    Updated patch for other querying function.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 30, 2014

    New changeset 40497cc445f4 by Antoine Pitrou in branch '3.4':
    Issue bpo-22759: Query methods on pathlib.Path() (exists(), is_dir(), etc.) now return False when the underlying stat call raises NotADirectoryError.
    https://hg.python.org/cpython/rev/40497cc445f4

    New changeset ff5f5fd230d3 by Antoine Pitrou in branch 'default':
    Issue bpo-22759: Query methods on pathlib.Path() (exists(), is_dir(), etc.) now return False when the underlying stat call raises NotADirectoryError.
    https://hg.python.org/cpython/rev/ff5f5fd230d3

    @pitrou
    Copy link
    Member

    pitrou commented Oct 30, 2014

    This is now fixed. Thanks for the report!

    @pitrou pitrou closed this as completed Oct 30, 2014
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants