From: Carlos Sanchez Lopez <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 18 Mar 2020 21:09:31 +0000 (-0700) Subject: Fix unexpected exception when enumerating a completely empty drive root (#33684) X-Git-Tag: submit/tizen/20210909.063632~9092 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=650acb57adfe8bf8791782c183ab06de3938d8a4;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Fix unexpected exception when enumerating a completely empty drive root (#33684) * Fix unexpected exception when enumerating a completely empty drive root. * Address PR suggestions: - Add NTStatus for file not found. - Use it in the switch case. Since it's a rare case, add it right above 'default'. * Remove hidden character causing build failure. It showed up after the file's encoding was changed to UTF8. --- diff --git a/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtStatus.cs b/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtStatus.cs index 2d51c44..413efdf 100644 --- a/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtStatus.cs +++ b/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtStatus.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -7,15 +7,16 @@ internal static partial class Interop internal class StatusOptions { // Error codes from ntstatus.h - internal const uint STATUS_SUCCESS = 0x00000000; - internal const uint STATUS_SOME_NOT_MAPPED = 0x00000107; - internal const uint STATUS_NO_MORE_FILES = 0x80000006; - internal const uint STATUS_INVALID_PARAMETER = 0xC000000D; - internal const uint STATUS_NO_MEMORY = 0xC0000017; - internal const uint STATUS_OBJECT_NAME_NOT_FOUND = 0xC0000034; - internal const uint STATUS_NONE_MAPPED = 0xC0000073; + internal const uint STATUS_SUCCESS = 0x00000000; + internal const uint STATUS_SOME_NOT_MAPPED = 0x00000107; + internal const uint STATUS_NO_MORE_FILES = 0x80000006; + internal const uint STATUS_INVALID_PARAMETER = 0xC000000D; + internal const uint STATUS_FILE_NOT_FOUND = 0xC000000F; + internal const uint STATUS_NO_MEMORY = 0xC0000017; + internal const uint STATUS_ACCESS_DENIED = 0xC0000022; + internal const uint STATUS_OBJECT_NAME_NOT_FOUND = 0xC0000034; + internal const uint STATUS_ACCOUNT_RESTRICTION = 0xC000006E; + internal const uint STATUS_NONE_MAPPED = 0xC0000073; internal const uint STATUS_INSUFFICIENT_RESOURCES = 0xC000009A; - internal const uint STATUS_ACCESS_DENIED = 0xC0000022; - internal const uint STATUS_ACCOUNT_RESTRICTION = 0xc000006e; } } diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Win32.cs b/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Win32.cs index 2fa89c0..b0cf0b3 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Win32.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Win32.cs @@ -42,6 +42,10 @@ namespace System.IO.Enumeration case Interop.StatusOptions.STATUS_SUCCESS: Debug.Assert(statusBlock.Information.ToInt64() != 0); return true; + // FILE_NOT_FOUND can occur when there are NO files in a volume root (usually there are hidden system files). + case Interop.StatusOptions.STATUS_FILE_NOT_FOUND: + DirectoryFinished(); + return false; default: int error = (int)Interop.NtDll.RtlNtStatusToDosError(status);