Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
</PropertyGroup>

<ItemGroup>
<Compile Remove="commands\management\ClearRecycleBinCommand.cs" />
<Compile Remove="commands\management\ControlPanelItemCommand.cs" />
<Compile Remove="commands\management\CommitTransactionCommand.cs" />
<Compile Remove="commands\management\Eventlog.cs" />
Expand All @@ -39,7 +38,6 @@
<Compile Remove="gen\ControlPanelResources.cs" />
<Compile Remove="gen\WmiResources.cs" />
<Compile Remove="gen\ManagementMshSnapInResources.cs" />
<Compile Remove="gen\ClearRecycleBinResources.cs" />
<Compile Remove="gen\ClipboardResources.cs" />

<EmbeddedResource Remove="resources\EventlogResources.resx" />
Expand All @@ -48,7 +46,6 @@
<EmbeddedResource Remove="resources\ControlPanelResources.resx" />
<EmbeddedResource Remove="resources\WmiResources.resx" />
<EmbeddedResource Remove="resources\ManagementMshSnapInResources.resx" />
<EmbeddedResource Remove="resources\ClearRecycleBinResources.resx" />
<EmbeddedResource Remove="resources\ClipboardResources.resx" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

#if !UNIX

namespace Microsoft.PowerShell.Commands
{
/// <summary>
Expand Down Expand Up @@ -224,25 +226,14 @@ private void EmptyRecycleBin(string drivePath)
progress.RecordType = ProgressRecordType.Processing;
WriteProgress(progress);

// no need to check result as a failure is returned only if recycle bin is already empty
uint result = NativeMethod.SHEmptyRecycleBin(IntPtr.Zero, drivePath,
NativeMethod.RecycleFlags.SHERB_NOCONFIRMATION |
NativeMethod.RecycleFlags.SHERB_NOPROGRESSUI |
NativeMethod.RecycleFlags.SHERB_NOSOUND);
int lastError = Marshal.GetLastWin32Error();

// update the progress bar to completed
progress.PercentComplete = 100;
progress.RecordType = ProgressRecordType.Completed;
WriteProgress(progress);

// 0 is for a successful operation
// 203 comes up when trying to empty an already emptied recyclebin
// 18 comes up when there are no more files in the given recyclebin
if (!(lastError == 0 || lastError == 203 || lastError == 18))
{
Win32Exception exception = new Win32Exception(lastError);
WriteError(new ErrorRecord(exception, "FailedToClearRecycleBin", ErrorCategory.InvalidOperation, "RecycleBin"));
}
}
}
}
Expand All @@ -261,3 +252,4 @@ internal enum RecycleFlags : uint
internal static extern uint SHEmptyRecycleBin(IntPtr hwnd, string pszRootPath, RecycleFlags dwFlags);
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ CmdletsToExport=@("Add-Content",
"Get-ComputerInfo",
"Get-TimeZone",
"Set-TimeZone",
"Get-HotFix")
"Get-HotFix",
"Clear-RecycleBin")
}
2 changes: 1 addition & 1 deletion test/powershell/engine/Basic/DefaultCommands.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Describe "Verify approved aliases list" -Tags "CI" {
"Cmdlet", "Clear-History", "", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", "Medium"
"Cmdlet", "Clear-Item", "", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", "Medium"
"Cmdlet", "Clear-ItemProperty", "", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", "Medium"
"Cmdlet", "Clear-RecycleBin", "", $($FullCLR ), "", "", ""
"Cmdlet", "Clear-RecycleBin", "", $($FullCLR -or $CoreWindows ), "", "", "High"
"Cmdlet", "Clear-Variable", "", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", "Medium"
"Cmdlet", "Compare-Object", "", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", "None"
"Cmdlet", "Complete-Transaction", "", $($FullCLR ), "", "", ""
Expand Down