mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Cleanup FileSystemProvider from runtime checks (#7655)
Replace runtime checks with compile time checks. Remove unneeded methods.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user