-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix New-Item to create correct symlink type (#2915) #3509
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
Now creates a file symlink to a file target and to an non-existent target, and a directory symlink to a directory target. Also updated tests.
| $fileInfo.Attributes -band $DirLinkMask | Should Be $DirLinkMask | ||
|
|
||
| # Remove the link explicitly to avoid broken symlink issue | ||
| Remove-Item $FullyQualifiedLink -Force |
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.
Is it still relevant?
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.
Sorry, is what still relevant?
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.
Here Remove-Item is workaround for a bug. Is the bug already fixed?
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.
Ah. I didn't know what "broken symlink issue" the author was referring to, so I didn't remove another dev's code. I am working on a Remove-Item issue, but I want to get this in so I can write tests using New-Item rather than shelling out a mklink command.
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 guess it's about problem with recursion when there are symlink. It is seems already fixed. It is not related with your PR.
Closed.
|
LGTM. |
|
@joeyaiello, @SteveL-MSFT Can whoever else needs to review this please do so? I have another issue that is waiting on this one to finish updating its PR, then I'll likely want to use changes from that one in yet another issue. |
|
cc @PowerShell/area-providers |
|
@jeffbi Thanks very much for great PR description! |
|
@mirichmo @SteveL-MSFT The PR block #3441. 😕 Could you please continue with the PR? |
|
@jeffbi could you please help me to understand how the change in |
|
@jeffbi Never mind, |
|
@daxian-dbw Thanks for quick response! |
Fix #2915
Now creates a file symlink to a file target and to an non-existent target, and a directory symlink to a directory target.
Creating Links with New-Item
The
New-Itemcmdlet allows for creating file system links.In general,
New-Itemcan create four types of links:-ItemTypeisHardLink-ItemTypeisSymbolicLinkand either the target exists and is a file, or the target does not existNew-Item -ItemType Symbolic Linkwill create a directory symbolic link, not a "plain" symbolic link.New-Item -ItemType Symbolic Linkwill always create a "plain" symbolic link, regardless of whether the target is a file or directory, or whether the target exists or not.-ItemTypeisSymbolicLinkand the target exists and is a directoryNew-Itemwill not create a directory symbolic link, even on an NTFS volume.New-Itemwill not create a directory junction, even on an NTFS volume.New-Itemwill begin to create the junction by creating the link directory. When the attempt to turn the newly-created directory into a junction fails,New-Itemwill delete the new directory and silently fail.The following table shows the types of links and targets the
New-Itemcmdlet can create on Windows:The following table shows the types of links and targets the
New-Itemcmdlet can create on Linux and OS X: