diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index c559c1f4c8e..bedf94e60eb 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -8135,19 +8135,7 @@ internal static bool WinIsHardLink(ref IntPtr handle) { BY_HANDLE_FILE_INFORMATION handleInfo; bool succeeded = InternalSymbolicLinkLinkCodeMethods.GetFileInformationByHandle(handle, out handleInfo); - - if (!succeeded) - { - int lastError = Marshal.GetLastWin32Error(); - throw new Win32Exception(lastError); - } - - if (handleInfo.NumberOfLinks > 1) - { - return true; - } - - return false; + return succeeded && (handleInfo.NumberOfLinks > 1); } private static string InternalGetTarget(SafeFileHandle handle) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 index 347de090281..d8c42850b64 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 @@ -76,14 +76,22 @@ Describe "Get-ChildItem" -Tags "CI" { Pop-Location } - It "Should have a the proper fields and be populated" { + It "Should have all the proper fields and be populated" { $var = Get-Childitem . $var.Name.Length | Should -BeGreaterThan 0 $var.Mode.Length | Should -BeGreaterThan 0 $var.LastWriteTime | Should -BeGreaterThan 0 $var.Length.Length | Should -BeGreaterThan 0 + } + It "Should have mode property populated for protected files on Windows" -Skip:(!$IsWindows) { + $files = Get-Childitem -Force ~\NT* + $files.Count | Should -BeGreaterThan 0 + foreach ($file in $files) + { + $file.Mode | Should -Not -BeNullOrEmpty + } } It "Should list files in sorted order" { @@ -153,11 +161,7 @@ Describe "Get-ChildItem" -Tags "CI" { (Get-ChildItem -Path $searchRoot -Directory -Recurse).Count | Should -Be 1 } - It "Should give .sys file if the fullpath is specified with hidden and force parameter" -Pending:$true { - # Enable the test after move to .Net Core 2.1.1 - # The tracking issue https://github.com/dotnet/corefx/issues/29782 - # - #It "Should give .sys file if the fullpath is specified with hidden and force parameter" -Skip:(!$IsWindows){ + It "Should give .sys file if the fullpath is specified with hidden and force parameter" -Skip:(!$IsWindows) { # Don't remove!!! It is special test for hidden and opened file with exclusive lock. $file = Get-ChildItem -path "$env:SystemDrive\\pagefile.sys" -Hidden $file | Should not be $null