Skip to content

Small fixes in FileSystemEnumerator for Windows.#126544

Open
teo-tsirpanis wants to merge 6 commits intodotnet:mainfrom
teo-tsirpanis:copilot/update-filesystem-enumerator-edits
Open

Small fixes in FileSystemEnumerator for Windows.#126544
teo-tsirpanis wants to merge 6 commits intodotnet:mainfrom
teo-tsirpanis:copilot/update-filesystem-enumerator-edits

Conversation

@teo-tsirpanis
Copy link
Copy Markdown
Contributor

@teo-tsirpanis teo-tsirpanis commented Apr 4, 2026

Note

This PR was created with the assistance of GitHub Copilot.

  • Replaced ineffective use of default(DisableMediaInsertionPrompt), with DisableMediaInsertionPrompt.Create(). Removed, after PR feedback.
    • No other similar cases were found.
  • The _buffer was updated to be backed by NativeMemory.AlignedAlloc instead of Marshal.AllocHGlobal. This makes the alignment requirement explicit and might increase performance.

Copilot AI review requested due to automatic review settings April 4, 2026 16:16
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 4, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Windows-specific implementation details in FileSystemEnumerator<TResult> to ensure the intended OS behaviors are actually applied and to make the NT query buffer’s alignment requirement explicit.

Changes:

  • Replace using (default(DisableMediaInsertionPrompt)) with using (DisableMediaInsertionPrompt.Create()) so the media insertion prompt suppression is actually enabled.
  • Allocate the directory query buffer via NativeMemory.AlignedAlloc(..., sizeof(ulong)) and free it via NativeMemory.AlignedFree, switching _buffer from IntPtr to void*.
  • Update the NtQueryDirectoryFile interop signature to accept void* for FileInformation, matching the updated buffer type.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs Uses the correct prompt-suppression factory and switches the query buffer to explicitly aligned native allocation.
src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtQueryDirectoryFile.cs Updates the P/Invoke signature to take a raw pointer for the output buffer.

Copy link
Copy Markdown
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

@JeremyKuhne PTAL

Thank you for your contribution @teo-tsirpanis !

// We'll only suppress the media insertion prompt on the topmost directory as that is the
// most likely scenario and we don't want to take the perf hit for large enumerations.
// (We weren't consistent with how we handled this historically.)
using (default(DisableMediaInsertionPrompt))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems like we were doing this on purpose. I will defer to @JeremyKuhne for review.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This has been broken for nearly 10 years I'd recommend just removing it- it clearly isn't impacting anyone.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@adamsitnik adamsitnik requested a review from JeremyKuhne April 15, 2026 08:32
Copy link
Copy Markdown
Member

@JeremyKuhne JeremyKuhne left a comment

Choose a reason for hiding this comment

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

Generally looks fine, see my comment on removing the broken suppression.

// We'll only suppress the media insertion prompt on the topmost directory as that is the
// most likely scenario and we don't want to take the perf hit for large enumerations.
// (We weren't consistent with how we handled this historically.)
using (default(DisableMediaInsertionPrompt))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This has been broken for nearly 10 years I'd recommend just removing it- it clearly isn't impacting anyone.

Copilot AI review requested due to automatic review settings April 15, 2026 22:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +89 to +93
// We need to initialize the directory handle up front to ensure
// we immediately throw IO exceptions for missing directory/etc.
_directoryHandle = CreateDirectoryHandle(_rootDirectory);
if (_directoryHandle == IntPtr.Zero)
_lastEntryFound = true;
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

Init() used to attempt to suppress the Windows removable-media insertion prompt when opening the top-level directory handle, but the PR removes the DisableMediaInsertionPrompt scope entirely. This doesn't match the PR description (“replace default(...) with Create()”) and leaves CreateDirectoryHandle(_rootDirectory) unprotected from prompting. Please wrap the directory-handle creation in using (DisableMediaInsertionPrompt.Create()) (keeping the existing intent of only doing this for the topmost directory to avoid perf impact).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @teo-tsirpanis !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.IO community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants