-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Resolve symlink target relative to the symlink instead of the working directory (#15235) #20943
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 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) |
|
So, um, is there a chance of anyone looking at this PR? It's been almost 4 months now without any response. |
18a2e31 to
c6b9cea
Compare
|
@SteveL-MSFT Apologies for pinging, but since @anmenaga, who is assigned, did not review the PR during the past 4 months, do you think you could review it instead? |
c6b9cea to
f6697ba
Compare
|
@MatejKafka sorry, I'm reviewing this now |
SteveL-MSFT
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.
|
@SteveL-MSFT Done. |
|
@SteveL-MSFT @anmenaga - can someone please review this? This has been an issue for years and I ran into this issue today. |
cfb54d4 to
5d81f1c
Compare
test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1
Outdated
Show resolved
Hide resolved
5d81f1c to
ad75b79
Compare
SteveL-MSFT
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
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 the user specified target path is like ./dir or .\dir, the value returned from Path.Combine would be like <sym-dir-path>{directory-separator}./dir or <sym-dir-path>{directory-separator}.\dir. This may not be a problem on Windows (which I'm not certain), but on Unix platform, a path like /home/user-a/.\temp cannot be resolved to /home/user-a/temp.
So, I think we should still remove the .\ or ./ prefix for a relative path.
Also, do we want to normalize directory separators used in the -Target? I mean, if user specifies .\subdir\dir on Linux, shall we normalize that to be ./subdir/dir?
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.
Also, do we want to normalize directory separators used in the
-Target? I mean, if user specifies.\subdir\diron Linux, shall we normalize that to be./subdir/dir?
There are already issues with path normalization on Unix since \ is valid char there. I think we shouldn't add one more.
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.
Thanks for the review, these are both good observations.
Just writing down my thoughts for the implementation:
- The path to the symlink is passed already resolved and pre-processed, but the
-Target/-Valueis passed as-is, since the previous layers don't know how it's used. - PowerShell supports both \ and / as directory separators on all platforms. Therefore, we should convert separators for the value that we store in the symlink target to match what rest of the shell does. This will prevent the user from symlinking to paths that contain
\on Linux/Mac, but imo that ship has sailed when PowerShell Core went with emulating\and consistency with the rest of PowerShell is now more important than allowing the user to create symlinks to files that they cannot create through PowerShell anyway. - Personally, I wouldn't do any other processing on
-Target. Don't see any reason to remove.//.\, since they should work fine as long as the separators are correct. - Since the file/directory distinction for symlinks is not a thing on Linux/Mac, we could just remove the whole logic around looking up the target and only use it on Windows. However, we return either
FileInfoorDirectoryInfofrom the command, so we need to know the type of the target anyway. - While looking at the implementation, I noticed that when creating a hardlink, we make
-Targetrelative to the current working directory. With the change implemented in this PR, this will be inconsistent with symlinks. Is that a problem? Shouldn't we also change hardlink creation to be consistent?
What needs to be implemented:
- unify slashes in
-Targetto the correct platform-specific separator before resolving the target
@daxian-dbw Do you agree?
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.
- Personally, I wouldn't do any other processing on
-Target. Don't see any reason to remove.//.\, since they should work fine as long as the separators are correct.
That's actually always annoyed the hell out of me to the point I manually remove them. I use ln.exe, which exposes the target via GUI.
I'd really appreciate if those were removed.
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.
@God-damnit-all In that case, just don't pass paths with ./ as -Target. Other people may have the opposite preference, and since both options behave identically in practice, I don't see any reason to force one or the other.
|
@daxian-dbw Fixed in latest commit. Please re-review. |
Remove created items after each test. Make the tests pass in strict mode.
75ff591 to
33c269a
Compare
daxian-dbw
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.
Looks good to me. Thanks @MatejKafka!

PR Summary
Fixes #15235.
PR Context
As described in the linked issue, the current implementation of symlink creation in the filesystem provider resolves relative symlink target paths relative to the working directory, instead of the location of the symlink. This PR fixes the issue by always resolving the path relative to the symlink. Additionally, since
Path.Combineis used now, the path should be correctly resolved even if it does not start with./or.\, which is currently not the case.It should be possible to add tests for this, but from a cursory look, there don't seem to by any tests of the filesystem provider touching the filesystem, so I did not add any.
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).