diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs index 8dd8f96bea..4cd8002989 100644 --- a/src/System.Management.Automation/engine/Utils.cs +++ b/src/System.Management.Automation/engine/Utils.cs @@ -984,38 +984,9 @@ namespace System.Management.Automation return NativeItemExists(path, out unusedIsDirectory, out unusedException); } + // This is done through P/Invoke since File.Exists and Directory.Exists pay 13% performance degradation + // through the CAS checks, and are terribly slow for network paths. internal static bool NativeItemExists(string path, out bool isDirectory, out Exception exception) - { - if (Platform.UseDotNetToQueryFileAttributes()) - { - // TODO:PSL replace by System.IO.File.GetAttributes - exception = null; - if (NativeDirectoryExists(path)) - { - isDirectory = true; - return true; - } - else if (NativeFileExists(path)) - { - isDirectory = false; - return true; - } - else - { - isDirectory = false; - return false; - } - } - else - { - // This is done through P/Invoke since File.Exists and Directory.Exists - // pay 13% performance degradation through the CAS checks, and are - // terribly slow for network paths. - return WinNativeItemExists(path,out isDirectory,out exception); - } - } - - internal static bool WinNativeItemExists(string path, out bool isDirectory, out Exception exception) { exception = null; @@ -1059,21 +1030,9 @@ namespace System.Management.Automation return true; } + // This is done through P/Invoke since we pay 13% performance degradation + // through the CAS checks required by File.Exists and Directory.Exists internal static bool NativeFileExists(string path) - { - if (Platform.UseDotNetToQueryFileAttributes()) - { - return System.IO.File.Exists(path); - } - else - { - // This is done through P/Invoke since we pay 13% performance degradation - // through the CAS checks required by File.Exists and Directory.Exists - return WinNativeFileExists(path); - } - } - - internal static bool WinNativeFileExists(string path) { bool isDirectory; Exception ioException; @@ -1090,18 +1049,6 @@ namespace System.Management.Automation // This is done through P/Invoke since we pay 13% performance degradation // through the CAS checks required by File.Exists and Directory.Exists internal static bool NativeDirectoryExists(string path) - { - if (Platform.UseDotNetToQueryFileAttributes()) - { - return System.IO.Directory.Exists(path); - } - else - { - return WinNativeDirectoryExists(path); - } - } - - internal static bool WinNativeDirectoryExists(string path) { bool isDirectory; Exception ioException; @@ -1116,31 +1063,6 @@ namespace System.Management.Automation } internal static void NativeEnumerateDirectory(string directory, out List directories, out List files) - { - if (Platform.UseDotNetToQueryFileAttributes()) - { - IEnumerable fileEnum = System.IO.Directory.EnumerateFiles(directory); - IEnumerable dirEnum = System.IO.Directory.EnumerateDirectories(directory); - - files = new List(); - directories = new List(); - - foreach (string entry in fileEnum) - { - files.Add(directory + "/" + entry); - } - foreach (string entry in dirEnum) - { - directories.Add(directory + "/" + entry); - } - } - else - { - WinNativeEnumerateDirectory(directory, out directories, out files); - } - } - - internal static void WinNativeEnumerateDirectory(string directory, out List directories, out List files) { IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1); NativeMethods.WIN32_FIND_DATA findData;