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 getting canonical filesystem paths with symlinks resolved, similar to the Linux realpath utility · Issue #10640 · PowerShell/PowerShell

Support getting canonical filesystem paths with symlinks resolved, similar to the Linux realpath utility #10640

New issue
Copy link
New issue
Copy link
Closed
Closed
Support getting canonical filesystem paths with symlinks resolved, similar to the Linux realpath utility#10640
Copy link
Labels
Area-FileSystem-Providerspecific to the FileSystem providerspecific to the FileSystem providerIssue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues

Description

@mklement0
Michael Klement (mklement0)
opened on Sep 27, 2019
Issue body actions

Summary of the new feature/enhancement

Provide the ability to resolve a filesystem path to its canonical path, such as by adding a -Canonical switch to the Convert-Path cmdlet.

In short: The idea is to allow you to answer the following question:

Given a (possibly relative, possibly PS-drive-based) file or directory path, where does the referenced file truly live, with symlinks, if any, resolved to their underlying target location, expressed as an absolute, native filesystem path?

For instance, say you want to know the canonical path of file
/User Guides And Information/ENERGY STAR.pdf on a Mac, which is /Library/Documentation/User Guides and Information.localized/ENERGY STAR.pdf
because /User Guides And Information is a directory symlink that targets
directory /Library/Documentation/User Guides and Information.localized

You could then do something like:

# WISHFUL THINKING
PS> Convert-Path -Canonical '/User Guides And Information/ENERGY STAR.pdf'

/Library/Documentation/User Guides and Information.localized/ENERGY STAR.pdf

On at least some Linux distros, the realpath utility provides this functionality, and you can also use readlink -f (or -m or -e).

Note that this new feature would complement the existing ability to inspect a symlink's (reparse point's) target via the .Target property of Get-Item / Get-ChildItem output, and also the proposed .ResolvedTarget property (see #13366 ).

The latter only operate on symlinks themselves, not on paths based on them (paths with additional components); additionally, the .Target property may be a relative path and $null if the input path isn't a symlink.
That is, (Get-Item '/User Guides And Information').Target works, because /User Guides And Information is itself a symlink, but (Get-Item '/User Guides And Information/ENERGY STAR.pdf').Target is $null, because the file inside the directory-symlink path itself isn't a symlink and therefore has no .Target property value.

Proposed technical implementation details (optional)

  • Windows: The GetFinalPathNameByHandle Windows API function provides this functionality.

  • macOS, Linux: haven't looked into it, but the GNU readlink utility implementation should provide pointers. The POSIX-mandated realpath() function provides this functionality (implemented as library functions on macOS and Linux; see man 3 realpath).

Decisions will also have to be made with respect to how final path components that don't exist yet are handled (i.e., a prefix of the path exists (an ancestral directory), but not the filename part or a relative subdirectory-based path), and how to handle broken symlinks; these cases are reflected in the GNU readlink utility's related -f / -e / -m options.

Note that Convert-Path in its current form doesn't support (partially) non-existent paths, but it's about time we changed that too - see #2993

Update: Implementing this functionality as a .NET API that this feature could build on, in the form of a new System.IO.Path.GetFullPath() overload, has now been proposed: dotnet/runtime#24271 (comment)

Reacted by Peter Vandivier

Activity

  1. Michael Klement (mklement0)
    added
    Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bug
    on Sep 27, 2019
  2. iSazonov commented on Sep 28, 2019

    @iSazonov
    Ilya (iSazonov)
    on Sep 28, 2019
    Collaborator
    More actions

    Michael Klement (@mklement0) Please look the old comment https://github.com/dotnet/coreclr/issues/2128#issuecomment-171879087 I think we need Core support. Currently Core team started .Net Core 5.0 design so it is good time to ask them for the feature.

  3. Ilya (iSazonov)
    added
    Area-Cmdlets-Management
    on Sep 28, 2019
  4. mklement0 commented on Aug 7, 2020

    @mklement0
    Michael Klement (mklement0)
    on Aug 7, 2020
    ContributorAuthor
    More actions

    There's a CoreFx symlink API proposal, where I've suggested a new System.IO.Path.GetFullPath() overload for canonical path resolution: dotnet/runtime#24271 (comment)

  5. Ilya (iSazonov)
    added
    Area-FileSystem-Providerspecific to the FileSystem providerspecific to the FileSystem provider
    on Nov 30, 2021
  6. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    microsoft-github-policy-serviceBot
    on Nov 16, 2023 – with Microsoft GitHub Policy Service
    Contributor
    More actions

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  7. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    microsoft-github-policy-serviceBot
    on Nov 16, 2023 – with Microsoft GitHub Policy Service
    Contributor
    More actions

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  8. microsoft-github-policy-service
    added
    Resolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or more
    on Nov 16, 2023
  9. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    microsoft-github-policy-serviceBot
    on Nov 16, 2023 – with Microsoft GitHub Policy Service
    Contributor
    More actions

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

    Reacted by Peter Vandivier
  10. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    microsoft-github-policy-serviceBot
    on Nov 23, 2023 – with Microsoft GitHub Policy Service
    Contributor
    More actions

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

  11. microsoft-github-policy-service
    closed this as completedon Nov 23, 2023
  12. Ryan Yates (kilasuit)
    added
    WG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues
    and removed
    WG-Cmdlets-Management
    on Jul 17, 2026
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

    Area-FileSystem-Providerspecific to the FileSystem providerspecific to the FileSystem providerIssue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — 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.