Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace FindFirstFileExW with FindFirstFileW #16840

Merged
merged 4 commits into from
Feb 5, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8073,8 +8073,10 @@ protected override bool ReleaseHandle()
private static extern bool FindClose(IntPtr handle);
}

[DllImport(PinvokeDllNames.FindFirstFileDllName, EntryPoint = "FindFirstFileExW", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern SafeFindHandle FindFirstFileEx(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, ref WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, int dwAdditionalFlags);
// We use 'FindFirstFileW' instead of 'FindFirstFileExW' because the latter doesn't work correctly with Unicode file names on FAT32.
// See https://github.com/PowerShell/PowerShell/issues/16804
[DllImport(PinvokeDllNames.FindFirstFileDllName, EntryPoint = "FindFirstFileW", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern SafeFindHandle FindFirstFile(string lpFileName, ref WIN32_FIND_DATA lpFindFileData);

internal enum FINDEX_INFO_LEVELS : uint
{
Expand Down Expand Up @@ -8278,7 +8280,7 @@ internal static bool IsReparsePointLikeSymlink(FileSystemInfo fileInfo)
fullPath = PathUtils.EnsureExtendedPrefix(fullPath);
}

using (SafeFindHandle handle = FindFirstFileEx(fullPath, FINDEX_INFO_LEVELS.FindExInfoBasic, ref data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, 0))
Copy link
Member

Choose a reason for hiding this comment

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

Can the structs FINDEX_INFO_LEVELS and FINDEX_SEARCH_OPS be removed now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They have been used for so long that one wonders if they will be needed again. :-)
They don't increase the size of the binaries, so I decided to leave them in until we were sure that .Net did what we needed.

Copy link
Member

Choose a reason for hiding this comment

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

It's better to remove all if they are not in use anymore. If for some reason we need to revert this change, all will be reverted back anyways.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am exploring now how we can make our providers better in particular File Provider and may need it again. I don't mind removing it for now though.

using (SafeFindHandle handle = FindFirstFile(fullPath, ref data))
{
if (handle.IsInvalid)
{
Expand Down