Skip to content

Pathlib .owner() and .group() methods fail on broken links #65521

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

Closed
inigoserna mannequin opened this issue Apr 21, 2014 · 4 comments
Closed

Pathlib .owner() and .group() methods fail on broken links #65521

inigoserna mannequin opened this issue Apr 21, 2014 · 4 comments
Labels
stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@inigoserna
Copy link
Mannequin

inigoserna mannequin commented Apr 21, 2014

BPO 21322
Nosy @pitrou
Files
  • pathlib-34-owner_group_fixed.diff
  • 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 2017-11-09.18:11:28.341>
    created_at = <Date 2014-04-21.16:42:49.821>
    labels = ['library', 'type-crash']
    title = 'Pathlib .owner() and .group() methods fail on broken links'
    updated_at = <Date 2017-11-09.18:11:28.340>
    user = 'https://bugs.python.org/inigoserna'

    bugs.python.org fields:

    activity = <Date 2017-11-09.18:11:28.340>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-11-09.18:11:28.341>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2014-04-21.16:42:49.821>
    creator = 'inigoserna'
    dependencies = []
    files = ['34992']
    hgrepos = []
    issue_num = 21322
    keywords = ['patch']
    message_count = 4.0
    messages = ['216950', '216971', '216995', '216996']
    nosy_count = 2.0
    nosy_names = ['pitrou', 'inigoserna']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue21322'
    versions = ['Python 3.4']

    @inigoserna
    Copy link
    Mannequin Author

    inigoserna mannequin commented Apr 21, 2014

    Pathlib .owner() and .group() methods fail on broken symlinks.

    They use:
    return pwd.getpwuid(self.stat().st_uid).pw_name
    and:
    return grp.getgrgid(self.stat().st_gid).gr_name

    It should be self.lstat().

    Attached simple fix as unified diff.

    @inigoserna inigoserna mannequin added stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Apr 21, 2014
    @pitrou
    Copy link
    Member

    pitrou commented Apr 21, 2014

    Most other Path methods operate on the link target, not the link itself, so I don't see why these methods would work otherwise.

    @inigoserna
    Copy link
    Mannequin Author

    inigoserna mannequin commented Apr 22, 2014

    Mainly, 2 reasons:

    • It can make programs crash *unexpectedly*

    • Pathlib should provide a complete and uniform API for dealing with all types of files. If not, users would need to use Pathlib for some kind of files and go to os and os.path for others, then why the reason to use Pathlib?

    @pitrou
    Copy link
    Member

    pitrou commented Apr 22, 2014

    • It can make programs crash *unexpectedly*

    A broken link is an error, so it's normal to have an exception raised
    here. An exception can always be caught if you were expecting the error.

    • Pathlib should provide a complete and uniform API for dealing with
      all types of files. If not, users would need to use Pathlib for some
      kind of files and go to os and os.path for others, then why the reason
      to use Pathlib?

    I sympathize with this. But you can already use Path.lstat() and inspect
    the st_uid and st_gid fields if you are really interested in the link's
    owner and group (rather than the target's).

    The fact that most Path methods dereference symlinks reflects the
    semantics of other common filesystem calls (such as those in the os
    module, or the underlying functions of the POSIX API).

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants