diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index 32585530ac..becede6497 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -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); diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index d8a2a9151d..5571c2ef64 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -7618,25 +7618,23 @@ namespace Microsoft.PowerShell.Commands /// The target of the reparse point public static IEnumerable 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; } /// @@ -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) {