Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2138,9 +2138,9 @@ protected override void NewItem(
// non-existing targets on either Windows or Linux.
try
{
exists = (itemType == ItemType.SymbolicLink)
? true // pretend it exists if we're making a symbolic link
: CheckItemExists(strTargetPath, out isDirectory);
exists = CheckItemExists(strTargetPath, out isDirectory);
if (itemType == ItemType.SymbolicLink)
exists = true; // pretend the target exists if we're making a symbolic link
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ Describe "New-Item with links" -Tags @('CI', 'RequireAdminOnWindows') {
$FullyQualifiedFile = Join-Path -Path $tmpDirectory -ChildPath $testfile
$FullyQualifiedFolder = Join-Path -Path $tmpDirectory -ChildPath $testfolder
$FullyQualifiedLink = Join-Path -Path $tmpDirectory -ChildPath $testlink
$SymLinkMask = [System.IO.FileAttributes]::ReparsePoint
$DirLinkMask = $SymLinkMask -bor [System.IO.FileAttributes]::Directory

BeforeEach {
Clean-State
Expand All @@ -144,6 +146,7 @@ Describe "New-Item with links" -Tags @('CI', 'RequireAdminOnWindows') {
$fileInfo = Get-ChildItem $FullyQualifiedLink
$fileInfo.Target | Should Match ([regex]::Escape($FullyQualifiedFile))
$fileInfo.LinkType | Should Be "SymbolicLink"
$fileInfo.Attributes -band $DirLinkMask | Should Be $SymLinkMask
}

It "Should create a symbolic link to a non-existing file without error" {
Expand All @@ -155,18 +158,20 @@ Describe "New-Item with links" -Tags @('CI', 'RequireAdminOnWindows') {
$fileInfo.Target | Should Be $target
Test-Path $fileInfo.Target | Should be $false
$fileInfo.LinkType | Should Be "SymbolicLink"
$fileInfo.Attributes -band $DirLinkMask | Should Be $SymLinkMask
}

It "Should create a symbolic link from directory without error" {
It "Should create a symbolic link to directory without error" {
New-Item -Name $testFolder -Path $tmpDirectory -ItemType directory
Test-Path $FullyQualifiedFolder | Should Be $true

New-Item -ItemType SymbolicLink -Target $FullyQualifiedFolder -Name $testlink -Path $tmpDirectory
Test-Path $FullyQualifiedLink | Should Be $true

$fileInfo = Get-ChildItem $FullyQualifiedLink
$fileInfo = Get-Item $FullyQualifiedLink
$fileInfo.Target | Should Match ([regex]::Escape($FullyQualifiedFolder))
$fileInfo.LinkType | Should Be "SymbolicLink"
$fileInfo.Attributes -band $DirLinkMask | Should Be $DirLinkMask

# Remove the link explicitly to avoid broken symlink issue
Remove-Item $FullyQualifiedLink -Force
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it still relevant?

Copy link
Contributor Author

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?

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Expand Down