-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Adds a .ResolvedTarget Property to File-System Items to Reflect a Symlink's Target as FileSystemInfo #16490
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
Conversation
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@hammy3502 Please look test fails. @mklement0 Could you please review? Is this addressed a behavior you requested? |
c57a5f3 to
d435fa6
Compare
|
My apologies for the unit tests! The PR should be good to go now. The one failing unit test here looks to be from upstream from when I last rebased, rather than this PR. EDIT: Looks like the unit tests have all passed; the PR should be good to go! |
|
/azp restart PowerShell-CI-macos |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Azure Pipelines successfully started running 1 pipeline(s). |
anamnavi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just had one recommendation to remove extra newline
src/System.Management.Automation/namespaces/FileSystemProvider.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/namespaces/FileSystemProvider.cs
Outdated
Show resolved
Hide resolved
|
It looks like the failed tests are from outside the scope of this PR, so we should still be good to merge. For clarification, all of the tests passed before 9c1b43f, which just removed an empty newline. EDIT: Looks like the failing unit tests were re-ran, and are good to go now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FileSystemInfo.ResolveLinkTarget may throw exception in various cases, such as when the current file system doesn't support reparsing point. The Target and FileSystemInfo.LinkedTarget don't throw, so we shouldn't throw either. Please handle the exception and return null in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a negative effects from the throw? Should we really mask the exceptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When calling the method on a file on a USB drive or micro sd drive, it will fail because the underlying filesystem doesn't support reparsing point. However, the behavior in that case should be returning the full path of the file.
Actually, this scenario should be handled, meaning when exception happens, it should decide when to return the FullName of the current FileSystemInfo, and when to return null.
[edited] For example, when the file is on a USB drive, ResolvedTarget should return the FullName of the file, even though exception will be thrown from fileSysInfo.ResolveLinkTarget(true).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would weird behavior in formatting output - if user see Target and LinkType properties are "empty" but ResolvedTarget is FullName.
And if I remember correctly .Net ResolveLinkTarget can return partially resolved path. https://github.com/dotnet/runtime/blob/12a8819eee9865eb38bca6c05fdece1053102854/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Windows.cs#L621-L627
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior I describe is what was asked from the issue:
If the item at hand isn't a symlink / reparse point, simply report its own full path - this allows unified treatment of symlinks and non-symlinks, as a simple way to get an item's full path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm about to push a commit that wraps a try-catch around the ResolveLinkTarget call and returning null, however I'm not sure in what situation ResolveLinkTarget would throw an exception and want to return FullName. It cleanly returns null when encountering something that isn't a symlink, and flash drives (by flashdrives, I'm assuming you mean the usage of FAT32/exFAT here) don't seem to support symlinks in any capacity. Am I missing something here? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to return FullName only if the FileSystemInfo is just a regular file/directory instead of a link.
Looking more into it, I found on portable drive with exFAT file system, ResolveLinkTarget(false) throws while ResolveLinkTarget(true) doesn't throw (see code here). So, maybe we don't really need the try / catch (IOException) here.
So, maybe we can do the following:
- if
ResolveLinkTarget(true)returnsnon-nullvalue, just return that value. (I see you check onsymbTarget.Existshere, but could it even be possible that the method returns a non-null value, but it doesn't exist?) - if
ResolveLinkTarget(true)returnsnullvalue, assuming that means it's not a link, and thus return theFullNameor the currentFileSystemInfodepending on what we want for return type. - if
ResolveLinkTarget(true)throws, then we assume that means it could be link, but something is wrong when resolving it. We just let the exception propagate in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the docstring for ResolveLinkTarget, it looks like we do need to check if it exists:
Returns: A System.IO.FileSystemInfo instance if the link exists, independently if the target exists or not
Besides that, the commit I mentioned earlier and the ones I just pushed should match the requested behavior!
src/System.Management.Automation/namespaces/FileSystemProvider.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/namespaces/FileSystemProvider.cs
Outdated
Show resolved
Hide resolved
|
@PowerShell/powershell-committee We need the committee to review the issue and PR on 2 behaviors of the proposed
|
|
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 10 days of this comment. |
|
Apologies for the slow response! I'll do my best to have the changes back within a couple days! |
|
@hammy3502 Thanks for your reply. I responded to your comments, and let's wait on the committee to decide the return type. |
|
@daxian-dbw Thank you so much! I handled the two threads you responded to, and I'll be eagerly awaiting a response from the committee! :) |
|
@PowerShell/powershell-committee reviewed this:
|
Co-authored-by: Ilya <darpa@yandex.ru>
4571f09 to
9a68c0f
Compare
|
@hammy3502 Please update the PR description to reflect new logic is implemented and open new issue in Documentation repository https://github.com/MicrosoftDocs/PowerShell-Docs.
|
|
@iSazonov I've updated the PR description, however I can't seem to find a page to propose any needed documentation changes (there doesn't appear to be any pages for |
I don't see all cases covered in #16490 (comment)
Since it is new addition I think it should be documented. If PowerShell documentation hasn't appropriate pages you can new doc issue as "idea" in doc repo. |
|
@daxian-dbw How could we re-run |
|
|
|
@daxian-dbw Thanks! This cgmanifest is reminiscent of the Files.wxs story. At first we had to update it manually every time. After that exhausted everyone, the update became automatic. 😄 I hope to see auto update soon! |
|
@daxian-dbw The action was finished but not reported again. 😟 |
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
|
Adding the ability for users to access a ResolvedTarget property on file and folder items, which returns a string representation of a path, depending on the type of file/folder:
|
|
@hammy3502 Thanks for your contribution! Please open doc issue. |
|
@iSazonov The docs issue has been opened! |
|
@hammy3502 Thanks for your contribution! |
|
🎉 Handy links: |
PR Summary
This PR addresses issue #13366 , adding the ability for users to access a
ResolvedTargetproperty on file and folder items, which returns a string representation of a path, depending on the type of file/folder:ResolvedTargetwill return a string referring to itself.ResolvedTargetwill return a string referring to the file/folder that the symbolic link points to.ResolvedTargetreturns a string referring to the broken destination.PR Context
This PR mainly addresses the problems described in #13366 , mainly that there is no easy way to resolve the path of a file if said file has a chance of being a symbolic link (and as a result, points to a different file in the end). This PR addresses this with the
ResolvedTargetproperty, which points to "the actual file" whether the file being referenced is a symbolic link or not.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).