Cleanup FileSystemProvider from runtime checks (#7655)

Replace runtime checks with compile time checks.
Remove unneeded methods.
This commit is contained in:
Ilya
2018-09-10 11:18:50 -07:00
committed by Travis Plunk
parent e74bd730fe
commit 433ec46efb
2 changed files with 10 additions and 30 deletions
@@ -497,12 +497,6 @@ namespace System.Management.Automation
return Unix.NativeMethods.IsSymLink(fileInfo.FullName);
}
internal static string NonWindowsInternalGetTarget(SafeFileHandle handle)
{
// SafeHandle is a Windows concept. Use the string version instead.
throw new PlatformNotSupportedException();
}
internal static string NonWindowsInternalGetTarget(string path)
{
return Unix.NativeMethods.FollowSymLink(path);
@@ -7618,25 +7618,23 @@ namespace Microsoft.PowerShell.Commands
/// <returns>The target of the reparse point</returns>
public static IEnumerable<string> GetTarget(PSObject instance)
{
FileSystemInfo fileSysInfo = instance.BaseObject as FileSystemInfo;
if (fileSysInfo != null)
if (instance.BaseObject is FileSystemInfo fileSysInfo)
{
if (Platform.IsWindows)
#if !UNIX
using (SafeFileHandle handle = OpenReparsePoint(fileSysInfo.FullName, FileDesiredAccess.GenericRead))
{
using (SafeFileHandle handle = OpenReparsePoint(fileSysInfo.FullName, FileDesiredAccess.GenericRead))
{
string linkTarget = InternalGetTarget(handle);
string linkTarget = WinInternalGetTarget(handle);
if (linkTarget != null)
return (new string[] { linkTarget });
if (linkTarget != null)
{
return (new string[] { linkTarget });
}
}
#endif
return InternalGetTarget(fileSysInfo.FullName);
}
else
return null;
return null;
}
/// <summary>
@@ -7964,18 +7962,6 @@ namespace Microsoft.PowerShell.Commands
return succeeded && (handleInfo.NumberOfLinks > 1);
}
private static string InternalGetTarget(SafeFileHandle handle)
{
if (Platform.IsWindows)
{
return WinInternalGetTarget(handle);
}
else
{
return Platform.NonWindowsInternalGetTarget(handle);
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods")]
private static string WinInternalGetTarget(SafeFileHandle handle)
{