mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Merge pull request #920 from PowerShell/removeitem
Fixes removal of symbolic link on Windows And don't ask confirmation on Linux
This commit is contained in:
@@ -3562,7 +3562,22 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
bool shouldRecurse = Recurse;
|
||||
if (!Recurse && hasChildren)
|
||||
bool treatAsFile = false;
|
||||
try
|
||||
{
|
||||
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(providerPath);
|
||||
if (!Platform.IsWindows && di != null && (di.Attributes & System.IO.FileAttributes.ReparsePoint) != 0)
|
||||
{
|
||||
shouldRecurse = false;
|
||||
treatAsFile = true;
|
||||
}
|
||||
}
|
||||
catch (System.IO.FileNotFoundException)
|
||||
{
|
||||
// not a directory
|
||||
}
|
||||
|
||||
if (!treatAsFile && !Recurse && hasChildren)
|
||||
{
|
||||
// Get the localized prompt string
|
||||
|
||||
|
||||
@@ -2858,7 +2858,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
//if this is a reparse point and force is not specified then warn user but dont remove the directory.
|
||||
if (((directory.Attributes & FileAttributes.ReparsePoint) != 0) && !Force)
|
||||
if (Platform.IsWindows && ((directory.Attributes & FileAttributes.ReparsePoint) != 0) && !Force)
|
||||
{
|
||||
String error = StringUtil.Format(FileSystemProviderStrings.DirectoryReparsePoint, directory.FullName);
|
||||
Exception e = new IOException(error);
|
||||
@@ -8452,10 +8452,24 @@ namespace Microsoft.PowerShell.Commands
|
||||
IntPtr dangerousHandle = handle.DangerousGetHandle();
|
||||
int bytesReturned;
|
||||
|
||||
// Do a FSCTL_GET_REPARSE_POINT first because the ReparseTag could be
|
||||
// IO_REPARSE_TAG_MOUNT_POINT or IO_REPARSE_TAG_SYMLINK.
|
||||
// Using the wrong one results in mismatched-tag error.
|
||||
|
||||
REPARSE_GUID_DATA_BUFFER junctionData = new REPARSE_GUID_DATA_BUFFER();
|
||||
ClrFacade.StructureToPtr<REPARSE_GUID_DATA_BUFFER>(junctionData, outBuffer, false);
|
||||
|
||||
result = DeviceIoControl(dangerousHandle, FSCTL_GET_REPARSE_POINT, IntPtr.Zero, 0,
|
||||
outBuffer, inOutBufferSize, out bytesReturned, IntPtr.Zero);
|
||||
if (!result)
|
||||
{
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
throw new Win32Exception(lastError);
|
||||
}
|
||||
|
||||
junctionData = ClrFacade.PtrToStructure<REPARSE_GUID_DATA_BUFFER>(outBuffer);
|
||||
junctionData.ReparseDataLength = 0;
|
||||
junctionData.DataBuffer = new char[MAX_REPARSE_SIZE];
|
||||
junctionData.ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;
|
||||
|
||||
ClrFacade.StructureToPtr<REPARSE_GUID_DATA_BUFFER>(junctionData, inBuffer, false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user