GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support different modes in os.path.realpath() · Issue #71189 · python/cpython

Support different modes in os.path.realpath() #71189

New issue
Copy link
New issue
Copy link
Closed
Closed
Support different modes in os.path.realpath()#71189
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@serhiy-storchaka
serhiy-storchaka
opened on May 11, 2016
Issue body actions
BPO 27002
Nosy @serhiy-storchaka, @barneygale
Files
  • realpath_mode.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 = None
    created_at = <Date 2016-05-11.18:54:44.165>
    labels = ['type-feature', 'library']
    title = 'Support different modes in posixpath.realpath()'
    updated_at = <Date 2021-04-08.00:42:45.008>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2021-04-08.00:42:45.008>
    actor = 'barneygale'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2016-05-11.18:54:44.165>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['42821']
    hgrepos = []
    issue_num = 27002
    keywords = ['patch']
    message_count = 2.0
    messages = ['265335', '390500']
    nosy_count = 2.0
    nosy_names = ['serhiy.storchaka', 'barneygale']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue27002'
    versions = ['Python 3.6']

    Linked PRs

    • gh-71189: Support all-but-last mode in os.path.realpath() #117562

    Activity

    1. serhiy-storchaka commented on May 11, 2016

      @serhiy-storchaka
      serhiy-storchaka
      on May 11, 2016
      MemberAuthor
      More actions

      For now posixpath.realpath() don't raise an exception if encounter broken link. Instead it just lefts broken link name and following path components unresolved. This is dangerous since broken link name can be collapsed with following ".." and resulting valid path can point at wrong location. May be this is even security issue.

      On other hand, Path.resolve() raises an exception when encounters broken link. This is not always desirable, there is a wish to make it more lenient. See bpo-19717 for more information.

      The readlink utility from GNU coreutils has three mode for resolving file path:

         -f, --canonicalize
                canonicalize by following every symlink in every component of the given name recursively; all but the last component must exist
      
         -e, --canonicalize-existing
                canonicalize by following every symlink in every component of the given name recursively, all components must exist
      
         -m, --canonicalize-missing
                canonicalize by following every symlink in every component of the given name recursively, without requirements on components existence
      

      Current behavior of posixpath.realpath() is matches (besides one minor detail) to readlink -m. The behavior of Path.resolve() matches readlink -e.

      Proposed preliminary patch implements the support of all three modes in posixpath.realpath(): CAN_MISSING, CAN_ALL_BUT_LAST and CAN_EXISTING. It exactly matches the behavior of readlink. The default mode is CAN_MISSING.

      There is minor behavior difference in the default mode. If there is a file "file", a link "link" that points to "file" and a broken link "broken", then "broken/../link" was resolved to "link" and now it is resolved to "file".

      The patch lacks the documentation. Ternary flag looks as not the best API. Binary flag would be better. But I don't know what can be dropped. CAN_MISSING is needed for compatibility, but it looks less useful and may be insecure (not more than normpath()). CAN_EXISTING and CAN_ALL_BUT_LAST is needed in different cases. I think that in many cases CAN_ALL_BUT_LAST is actually needed instead of CAN_MISSING.

      After resolving this issue the solution will be adopted for Path.resolve().

    2. serhiy-storchaka
      added
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancementA feature request or enhancement
      on May 11, 2016
    3. barneygale commented on Apr 8, 2021

      @barneygale
      barneygalemannequin
      on Apr 8, 2021
      Mannequin
      More actions

      Just stumbled upon this issue after submitting a PR: #25264

      In my PR, strict=False is like --canonicalize-missing, and strict=True is like --canonicalize-existing.

      Looks like our patches are along similar lines. I've missed a trick by not calling stat() to trigger the ELOOP error.

    4. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    5. serhiy-storchaka
      added a commit that references this issue on Apr 5, 2024

      pythongh-71189: Support all-but-last mode in posixpath.realpath()

      e8c859c
    6. serhiy-storchaka
      changed the title [-]Support different modes in posixpath.realpath()[/-] [+]Support different modes in os.path.realpath()[/+] on May 20, 2025
    7. serhiy-storchaka
      added a commit that references this issue on Jul 30, 2025

      gh-71189: Support all-but-last mode in os.path.realpath() (GH-117562)

      9d3b53c
    8. serhiy-storchaka
      closed this as completedon Jul 31, 2025
    9. Agent-Hellboy
      added a commit that references this issue on Aug 19, 2025

      pythongh-71189: Support all-but-last mode in os.path.realpath() (pyth…

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

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        You are visitor 01402503 — GeezerVison does not store the pages you look up.
        Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.