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

remove dead code from nativemethods #10840

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions src/Framework/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
6 changes: 3 additions & 3 deletions src/MSBuildTaskHost/FileSystem/MSBuildTaskHostFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class MSBuildTaskHostFileSystem : IFileSystem

public bool FileOrDirectoryExists(string path)
{
return NativeMethodsShared.FileOrDirectoryExists(path);
return FileExists(path) || DirectoryExists(path);
}

public FileAttributes GetAttributes(string path)
Expand All @@ -35,7 +35,7 @@ public DateTime GetLastWriteTimeUtc(string path)

public bool DirectoryExists(string path)
{
return NativeMethodsShared.DirectoryExists(path);
return Directory.Exists(path);
}

public IEnumerable<string> EnumerateDirectories(string path, string searchPattern = "*", SearchOption searchOption = SearchOption.TopDirectoryOnly)
Expand Down Expand Up @@ -77,7 +77,7 @@ public IEnumerable<string> EnumerateFileSystemEntries(string path, string search

public bool FileExists(string path)
{
return NativeMethodsShared.FileExists(path);
return File.Exists(path);
}
}
}
12 changes: 10 additions & 2 deletions src/Shared/FileSystem/WindowsFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public override IEnumerable<string> 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)
Expand All @@ -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)
Expand Down