Skip to content

Enable Get-ChildItem to produce Mode property even if cannot determine if hardlink - #7355

Merged
Dongbo Wang (daxian-dbw) merged 2 commits into
PowerShell:masterfrom
SteveL-MSFT:get-childitem-mode
Jul 26, 2018
Merged

Enable Get-ChildItem to produce Mode property even if cannot determine if hardlink#7355
Dongbo Wang (daxian-dbw) merged 2 commits into
PowerShell:masterfrom
SteveL-MSFT:get-childitem-mode

Conversation

@SteveL-MSFT

@SteveL-MSFT Steve Lee (SteveL-MSFT) commented Jul 25, 2018

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor

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

@SteveL-MSFT

Copy link
Copy Markdown
Member Author

PRASOON KARUNAN V (@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
Copy Markdown
Member

PRASOON KARUNAN V (@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
Copy Markdown
Contributor

Dongbo Wang (@daxian-dbw) Thanks for the clarification.

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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
Dongbo Wang (daxian-dbw) merged commit b767d5c into PowerShell:master Jul 26, 2018
@TravisEz13

Copy link
Copy Markdown
Member

Dongbo Wang (@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
Steve Lee (SteveL-MSFT) deleted the get-childitem-mode branch August 31, 2018 20:33
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
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