Skip to content

Commit b767d5c

Browse files
SteveL-MSFTdaxian-dbw
authored andcommitted
Fix IsHardLink() to return false instead of throwing exception when unable to determine (PowerShell#7355)
1 parent 20f7577 commit b767d5c

2 files changed

Lines changed: 11 additions & 19 deletions

File tree

src/System.Management.Automation/namespaces/FileSystemProvider.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8111,19 +8111,7 @@ internal static bool WinIsHardLink(ref IntPtr handle)
81118111
{
81128112
BY_HANDLE_FILE_INFORMATION handleInfo;
81138113
bool succeeded = InternalSymbolicLinkLinkCodeMethods.GetFileInformationByHandle(handle, out handleInfo);
8114-
8115-
if (!succeeded)
8116-
{
8117-
int lastError = Marshal.GetLastWin32Error();
8118-
throw new Win32Exception(lastError);
8119-
}
8120-
8121-
if (handleInfo.NumberOfLinks > 1)
8122-
{
8123-
return true;
8124-
}
8125-
8126-
return false;
8114+
return succeeded && (handleInfo.NumberOfLinks > 1);
81278115
}
81288116

81298117
private static string InternalGetTarget(SafeFileHandle handle)

test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,22 @@ Describe "Get-ChildItem" -Tags "CI" {
7676
Pop-Location
7777
}
7878

79-
It "Should have a the proper fields and be populated" {
79+
It "Should have all the proper fields and be populated" {
8080
$var = Get-Childitem .
8181

8282
$var.Name.Length | Should -BeGreaterThan 0
8383
$var.Mode.Length | Should -BeGreaterThan 0
8484
$var.LastWriteTime | Should -BeGreaterThan 0
8585
$var.Length.Length | Should -BeGreaterThan 0
86+
}
8687

88+
It "Should have mode property populated for protected files on Windows" -Skip:(!$IsWindows) {
89+
$files = Get-Childitem -Force ~\NT*
90+
$files.Count | Should -BeGreaterThan 0
91+
foreach ($file in $files)
92+
{
93+
$file.Mode | Should -Not -BeNullOrEmpty
94+
}
8795
}
8896

8997
It "Should list files in sorted order" {
@@ -153,11 +161,7 @@ Describe "Get-ChildItem" -Tags "CI" {
153161
(Get-ChildItem -Path $searchRoot -Directory -Recurse).Count | Should -Be 1
154162
}
155163

156-
It "Should give .sys file if the fullpath is specified with hidden and force parameter" -Pending:$true {
157-
# Enable the test after move to .Net Core 2.1.1
158-
# The tracking issue https://github.com/dotnet/corefx/issues/29782
159-
#
160-
#It "Should give .sys file if the fullpath is specified with hidden and force parameter" -Skip:(!$IsWindows){
164+
It "Should give .sys file if the fullpath is specified with hidden and force parameter" -Skip:(!$IsWindows) {
161165
# Don't remove!!! It is special test for hidden and opened file with exclusive lock.
162166
$file = Get-ChildItem -path "$env:SystemDrive\\pagefile.sys" -Hidden
163167
$file | Should not be $null

0 commit comments

Comments
 (0)