Fix New-Item to create correct symlink type (#2915)#3509
Fix New-Item to create correct symlink type (#2915)#3509daxian-dbw merged 1 commit intoPowerShell:masterfrom jeffbi:new-item-2915
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.
Here Remove-Item is workaround for a bug. Is the bug already fixed?
There was a problem hiding this comment.
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.
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: