Skip to content

pathlib.Path.glob causes OSError encountering symlinks to long filenames #87695

Description

@ericfrederich
BPO 43529
Nosy @ericfrederich
Files
  • uhoh.py: Reproduces bug
  • 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 = None
    created_at = <Date 2021-03-17.15:23:36.025>
    labels = ['3.7', '3.8', '3.9', '3.10']
    title = 'pathlib.Path.glob causes OSError encountering symlinks to long filenames'
    updated_at = <Date 2021-03-19.11:28:12.066>
    user = 'https://github.com/ericfrederich'

    bugs.python.org fields:

    activity = <Date 2021-03-19.11:28:12.066>
    actor = 'eric.frederich'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2021-03-17.15:23:36.025>
    creator = 'eric.frederich'
    dependencies = []
    files = ['49884']
    hgrepos = []
    issue_num = 43529
    keywords = []
    message_count = 3.0
    messages = ['388927', '388928', '389073']
    nosy_count = 1.0
    nosy_names = ['eric.frederich']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue43529'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10']

    Linked PRs

    Activity

    1. ericfrederich commented on Mar 17, 2021

      ericfrederichmannequin
      MannequinAuthor

      Calling pathlib.Path.glob("**/*) on a directory containing a symlink which resolves to a very long filename causes OSError.

      This is completely avoidable since symlinks are not followed anyway.

      In pathlib.py, the _RecursiveWildcardSelector has a method _iterate_directories which first calls entry.is_dir() prior to excluding based on entry.is_symlink().

      It's the entry.is_dir() which is failing.
      If the check for entry.is_symlink() were to happen first this error would be avoided.

      It's worth noting that on Linux "ls -l bad_link" works fine.
      Also "find /some/path/containing/bad/link" works fine.
      You do get an error however when running "ls bad_link"
      I believe Python's glob() should act like "find" on Linux and not fail.
      Because it is explicitly ignoring symlinks anyway, it has no business calling is_dir() on a symlink.

      I have attached a file which reproduces this problem. It's meant to be ran inside of an empty directory.

    2. ericfrederich commented on Mar 17, 2021

      ericfrederichmannequin
      MannequinAuthor

      I verified against all versions available for me to select.
      For 3.10 I used the 3.10-rc Docker image.

    3. ericfrederich commented on Mar 19, 2021

      ericfrederichmannequin
      MannequinAuthor

      I'm happy to create a pull request but would need some help.

      Looking at that routine it has changed over time and I cannot simply create a single patch against 3.6 and have it merge cleanly into newer versions.

      I'd need help explaining the process

    4. transferred this issue fromon Apr 10, 2022
    5. added 4 commits that reference this issue on May 8, 2023
    6. added 2 commits that reference this issue on May 10, 2023
    7. added a commit that references this issue on May 10, 2023
    8. barneygale commented on May 10, 2023

      @barneygale
      Contributor

      Fixed in 3.12: #104292 / a33ce66

      Backported to 3.11: #104362 / 846a23d

    9. added a commit that references this issue on May 11, 2023
    10. encukou commented on May 23, 2023

      @encukou
      Member

      Note that this is "fixed" (the error is ignored) in 3.8+ in #79487

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions