From 66ad0a3fef30896bdefd2b6d4e4fe2b54f2c5519 Mon Sep 17 00:00:00 2001 From: kasperk81 <83082615+kasperk81@users.noreply.github.com> Date: Thu, 17 Oct 2024 22:23:39 +0300 Subject: [PATCH 1/4] remove dead code from nativemethods --- src/Framework/NativeMethods.cs | 49 ---------------------------------- 1 file changed, 49 deletions(-) diff --git a/src/Framework/NativeMethods.cs b/src/Framework/NativeMethods.cs index bbc62463b1e..ac4b373fba5 100644 --- a/src/Framework/NativeMethods.cs +++ b/src/Framework/NativeMethods.cs @@ -1821,53 +1821,4 @@ internal static extern bool GetFileTime( internal static extern int symlink(string oldpath, string newpath); #endregion - - #region helper methods - - internal static bool DirectoryExists(string fullPath) - { - return IsWindows - ? DirectoryExistsWindows(fullPath) - : Directory.Exists(fullPath); - } - - [SupportedOSPlatform("windows")] - internal static bool DirectoryExistsWindows(string fullPath) - { - WIN32_FILE_ATTRIBUTE_DATA data = new WIN32_FILE_ATTRIBUTE_DATA(); - bool success = GetFileAttributesEx(fullPath, 0, ref data); - return success && (data.fileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; - } - - internal static bool FileExists(string fullPath) - { - return IsWindows - ? FileExistsWindows(fullPath) - : File.Exists(fullPath); - } - - [SupportedOSPlatform("windows")] - internal static bool FileExistsWindows(string fullPath) - { - WIN32_FILE_ATTRIBUTE_DATA data = new WIN32_FILE_ATTRIBUTE_DATA(); - bool success = GetFileAttributesEx(fullPath, 0, ref data); - return success && (data.fileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0; - } - - internal static bool FileOrDirectoryExists(string path) - { - return IsWindows - ? FileOrDirectoryExistsWindows(path) - : File.Exists(path) || Directory.Exists(path); - } - - [SupportedOSPlatform("windows")] - internal static bool FileOrDirectoryExistsWindows(string path) - { - WIN32_FILE_ATTRIBUTE_DATA data = new WIN32_FILE_ATTRIBUTE_DATA(); - return GetFileAttributesEx(path, 0, ref data); - } - - #endregion - } From a287a60c67aa003f09e3a927afbc743a7bfa718d Mon Sep 17 00:00:00 2001 From: kasperk81 <83082615+kasperk81@users.noreply.github.com> Date: Thu, 17 Oct 2024 22:24:56 +0300 Subject: [PATCH 2/4] match file.exists --- src/Shared/FileSystem/WindowsFileSystem.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Shared/FileSystem/WindowsFileSystem.cs b/src/Shared/FileSystem/WindowsFileSystem.cs index 1493d0f29a8..ad98f6907a7 100644 --- a/src/Shared/FileSystem/WindowsFileSystem.cs +++ b/src/Shared/FileSystem/WindowsFileSystem.cs @@ -55,7 +55,11 @@ public override IEnumerable EnumerateFileSystemEntries(string path, stri public override bool DirectoryExists(string path) { - return NativeMethodsShared.DirectoryExistsWindows(path); +#if NETFRAMEWORK + return Microsoft.IO.Directory.Exists(path); +#else + return Directory.Exists(path); +#endif } public override bool FileExists(string path) @@ -69,7 +73,11 @@ public override bool FileExists(string path) public override bool FileOrDirectoryExists(string path) { - return NativeMethodsShared.FileOrDirectoryExistsWindows(path); +#if NETFRAMEWORK + return FileExists(path) || DirectoryExists(path); +#else + return Path.Exists(path); +#endif } public override DateTime GetLastWriteTimeUtc(string path) From a1c661d00e59838bfc35c2ba5b357c6a28b47980 Mon Sep 17 00:00:00 2001 From: kasperk81 <83082615+kasperk81@users.noreply.github.com> Date: Thu, 17 Oct 2024 22:41:26 +0300 Subject: [PATCH 3/4] - --- .../FileSystem/MSBuildTaskHostFileSystem.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/MSBuildTaskHost/FileSystem/MSBuildTaskHostFileSystem.cs b/src/MSBuildTaskHost/FileSystem/MSBuildTaskHostFileSystem.cs index 46cb997dc51..e211857a448 100644 --- a/src/MSBuildTaskHost/FileSystem/MSBuildTaskHostFileSystem.cs +++ b/src/MSBuildTaskHost/FileSystem/MSBuildTaskHostFileSystem.cs @@ -20,7 +20,11 @@ internal class MSBuildTaskHostFileSystem : IFileSystem public bool FileOrDirectoryExists(string path) { - return NativeMethodsShared.FileOrDirectoryExists(path); +#if NETFRAMEWORK + return FileExists(path) || DirectoryExists(path); +#else + return Path.Exists(path); +#endif } public FileAttributes GetAttributes(string path) @@ -35,7 +39,11 @@ public DateTime GetLastWriteTimeUtc(string path) public bool DirectoryExists(string path) { - return NativeMethodsShared.DirectoryExists(path); +#if NETFRAMEWORK + return Microsoft.IO.Directory.Exists(path); +#else + return Directory.Exists(path); +#endif } public IEnumerable EnumerateDirectories(string path, string searchPattern = "*", SearchOption searchOption = SearchOption.TopDirectoryOnly) @@ -77,7 +85,11 @@ public IEnumerable EnumerateFileSystemEntries(string path, string search public bool FileExists(string path) { - return NativeMethodsShared.FileExists(path); +#if NETFRAMEWORK + return Microsoft.IO.File.Exists(path); +#else + return File.Exists(path); +#endif } } } From 236b0948ffcaaf510da2f75d33baf6a89a59441b Mon Sep 17 00:00:00 2001 From: kasperk81 <83082615+kasperk81@users.noreply.github.com> Date: Fri, 18 Oct 2024 00:45:16 +0300 Subject: [PATCH 4/4] - --- .../FileSystem/MSBuildTaskHostFileSystem.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/MSBuildTaskHost/FileSystem/MSBuildTaskHostFileSystem.cs b/src/MSBuildTaskHost/FileSystem/MSBuildTaskHostFileSystem.cs index e211857a448..03c73595094 100644 --- a/src/MSBuildTaskHost/FileSystem/MSBuildTaskHostFileSystem.cs +++ b/src/MSBuildTaskHost/FileSystem/MSBuildTaskHostFileSystem.cs @@ -20,11 +20,7 @@ internal class MSBuildTaskHostFileSystem : IFileSystem public bool FileOrDirectoryExists(string path) { -#if NETFRAMEWORK return FileExists(path) || DirectoryExists(path); -#else - return Path.Exists(path); -#endif } public FileAttributes GetAttributes(string path) @@ -39,11 +35,7 @@ public DateTime GetLastWriteTimeUtc(string path) public bool DirectoryExists(string path) { -#if NETFRAMEWORK - return Microsoft.IO.Directory.Exists(path); -#else return Directory.Exists(path); -#endif } public IEnumerable EnumerateDirectories(string path, string searchPattern = "*", SearchOption searchOption = SearchOption.TopDirectoryOnly) @@ -85,11 +77,7 @@ public IEnumerable EnumerateFileSystemEntries(string path, string search public bool FileExists(string path) { -#if NETFRAMEWORK - return Microsoft.IO.File.Exists(path); -#else return File.Exists(path); -#endif } } }