Skip to content

Conversation

@SteveL-MSFT
Copy link
Member

@SteveL-MSFT SteveL-MSFT commented Jul 25, 2018

PR Summary

Some files in the user directory on Windows such as 'NTUSER.DAT' cause the IsHardLink() check to fail with an INVALID_HANDLE win32 error. This causes the Mode property to fail being defined even though it was fine up until that last api call. I don't see any reason to throw an exception if the hard link check fails, instead just return false since we cannot determine it's a hardlink.

Fix #7353

PR Checklist

@kvprasoon
Copy link
Contributor

@SteveL-MSFT What will be the output after this change, will it exclude such files ?

@SteveL-MSFT
Copy link
Member Author

@kvprasoon no. With this change, it should work the same as with Windows PowerShell before we added the check for hard links.

@daxian-dbw
Copy link
Member

@kvprasoon It will not exclude such files. The mode for such files will not have l in it when the call to GetFileInformationByHandle fails, that's all.

@kvprasoon
Copy link
Contributor

@daxian-dbw Thanks for the clarification.

Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

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

LGTM with one minor comment.

}
}

return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could remove if-s:

bool succeeded = InternalSymbolicLinkLinkCodeMethods.GetFileInformationByHandle(handle, out handleInfo);

return succeeded && (handleInfo.NumberOfLinks > 1);

Copy link
Member Author

Choose a reason for hiding this comment

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

Good suggestion. Will update.

@daxian-dbw daxian-dbw merged commit b767d5c into PowerShell:master Jul 26, 2018
@TravisEz13
Copy link
Member

@daxian-dbw FYI, I had to go back to the PR to figure this one out. The message used to commit wasn't as good as the PR title

@SteveL-MSFT SteveL-MSFT deleted the get-childitem-mode branch August 31, 2018 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PowerShell v6.1.0-preview.4: Broken output for Get-ChildItem

6 participants