Avoid an exception if file system does not support reparse points (#13634)

This commit is contained in:
Ilya
2020-12-03 11:24:49 -08:00
committed by GitHub
parent 99e527bc0a
commit 2804576840
@@ -7837,8 +7837,6 @@ namespace Microsoft.PowerShell.Commands
// data is 16KB, plus there's a header.
private const int MAX_REPARSE_SIZE = (16 * 1024) + REPARSE_GUID_DATA_BUFFER_HEADER_SIZE;
private const int ERROR_NOT_A_REPARSE_POINT = 4390;
private const int FSCTL_GET_REPARSE_POINT = 0x000900A8;
private const int FSCTL_SET_REPARSE_POINT = 0x000900A4;
@@ -8153,16 +8151,20 @@ namespace Microsoft.PowerShell.Commands
// Get Buffer size
IntPtr dangerousHandle = handle.DangerousGetHandle();
bool result = DeviceIoControl(dangerousHandle, FSCTL_GET_REPARSE_POINT,
IntPtr.Zero, 0, outBuffer, outBufferSize, out bytesReturned, IntPtr.Zero);
bool result = DeviceIoControl(
dangerousHandle,
FSCTL_GET_REPARSE_POINT,
InBuffer: IntPtr.Zero,
nInBufferSize: 0,
outBuffer,
outBufferSize,
out bytesReturned,
lpOverlapped: IntPtr.Zero);
if (!result)
{
int lastError = Marshal.GetLastWin32Error();
if (lastError == ERROR_NOT_A_REPARSE_POINT)
linkType = null;
else
throw new Win32Exception(lastError);
// It's not a reparse point or the file system doesn't support reparse points.
return IsHardLink(ref dangerousHandle) ? "HardLink" : null;
}
REPARSE_DATA_BUFFER_SYMBOLICLINK reparseDataBuffer = Marshal.PtrToStructure<REPARSE_DATA_BUFFER_SYMBOLICLINK>(outBuffer);
@@ -8182,7 +8184,7 @@ namespace Microsoft.PowerShell.Commands
break;
default:
linkType = IsHardLink(ref dangerousHandle) ? "HardLink" : null;
linkType = null;
break;
}
@@ -8399,16 +8401,20 @@ namespace Microsoft.PowerShell.Commands
// According to MSDN guidance DangerousAddRef() and DangerousRelease() have been used.
handle.DangerousAddRef(ref success);
bool result = DeviceIoControl(handle.DangerousGetHandle(), FSCTL_GET_REPARSE_POINT,
IntPtr.Zero, 0, outBuffer, outBufferSize, out bytesReturned, IntPtr.Zero);
bool result = DeviceIoControl(
handle.DangerousGetHandle(),
FSCTL_GET_REPARSE_POINT,
InBuffer: IntPtr.Zero,
nInBufferSize: 0,
outBuffer,
outBufferSize,
out bytesReturned,
lpOverlapped: IntPtr.Zero);
if (!result)
{
int lastError = Marshal.GetLastWin32Error();
if (lastError == ERROR_NOT_A_REPARSE_POINT)
return null;
throw new Win32Exception(lastError);
// It's not a reparse point or the file system doesn't support reparse points.
return null;
}
string targetDir = null;