Title: Support getting canonical filesystem paths with symlinks resolved, similar to the Linux realpath utility · Issue #10640 · PowerShell/PowerShell · GitHub
Open Graph Title: Support getting canonical filesystem paths with symlinks resolved, similar to the Linux realpath utility · Issue #10640 · PowerShell/PowerShell
X Title: Support getting canonical filesystem paths with symlinks resolved, similar to the Linux realpath utility · Issue #10640 · PowerShell/PowerShell
Description: 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 q...
Open Graph Description: 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 i...
X Description: 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 i...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/10640
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support getting canonical filesystem paths with symlinks resolved, similar to the Linux realpath utility","articleBody":"# Summary of the new feature/enhancement\r\n\r\nProvide the ability to resolve a filesystem path to its canonical path, such as by adding a `-Canonical` switch to the `Convert-Path` cmdlet.\r\n\r\nIn short: The idea is to allow you to answer the following question: \r\n\r\n**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?**\r\n\r\nFor instance, say you want to know the canonical path of file \r\n`/User Guides And Information/ENERGY STAR.pdf` on a Mac, which is `/Library/Documentation/User Guides and Information.localized/ENERGY STAR.pdf`\r\nbecause `/User Guides And Information` is a directory symlink that targets\r\ndirectory `/Library/Documentation/User Guides and Information.localized`\r\n\r\nYou could then do something like:\r\n\r\n```powershell\r\n# WISHFUL THINKING\r\nPS> Convert-Path -Canonical '/User Guides And Information/ENERGY STAR.pdf'\r\n\r\n/Library/Documentation/User Guides and Information.localized/ENERGY STAR.pdf\r\n```\r\n\r\nOn at least some Linux distros, the `realpath` utility provides this functionality, and you can also use `readlink -f` (or `-m` or `-e`).\r\n\r\nNote 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 ).\r\n\r\nThe 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.\r\nThat 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.\r\n\r\n\r\n# Proposed technical implementation details (optional)\r\n\r\n* Windows: The [`GetFinalPathNameByHandle`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlew) Windows API function provides this functionality.\r\n\r\n* macOS, Linux: ~~haven't looked into it, but the GNU `readlink` utility implementation should provide pointers~~. The POSIX-mandated [`realpath()` function](https://pubs.opengroup.org/onlinepubs/9699919799/functions/realpath.html) provides this functionality (implemented as library functions on macOS and Linux; see `man 3 realpath`).\r\n\r\nDecisions 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.\r\n\r\nNote 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\r\n\r\n_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: https://github.com/dotnet/runtime/issues/24271#issuecomment-670709364","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2019-09-27T19:21:34Z","url":"https://github.com/PowerShell/PowerShell/issues/10640"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2fe169bc-d28f-5f77-558c-070fe2300656 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BB7C:6B763:CD205D:1257F12:6AFDABDB |
| html-safe-nonce | 25e2ea8c9f74c6b4ff00b400f6b2943a47e1a83df6be36da7e16b19deedad317 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjdDOjZCNzYzOkNEMjA1RDoxMjU3RjEyOjZBRkRBQkRCIiwidmlzaXRvcl9pZCI6Ijg5OTAwOTMwNTg5MjYwMjk3ODgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 809daa86d88471a5dcbd3ef0542abbd78a8e494160559de5c044a6459467739d |
| hovercard-subject-tag | issue:499609460 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/10640/issue_layout |
| twitter:image | https://opengraph.githubassets.com/81a1e97ee22bd819ac5c81991df9dbd2c008366dbab1621c6d72e4d612143321/PowerShell/PowerShell/issues/10640 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/81a1e97ee22bd819ac5c81991df9dbd2c008366dbab1621c6d72e4d612143321/PowerShell/PowerShell/issues/10640 |
| og:image:alt | 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 i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | bc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0ddf53eb35c87f1f8df13dbf75c3bdadbfc6e969 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width