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
46 changes: 46 additions & 0 deletions src/System.Management.Automation/namespaces/FileSystemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public sealed partial class FileSystemProvider : NavigationCmdletProvider,
private const int FILETRANSFERSIZE = 4 * 1024 * 1024;

private const int COPY_FILE_ACTIVITY_ID = 0;
private const int REMOVE_FILE_ACTIVITY_ID = 0;

// The name of the key in an exception's Data dictionary when attempting
// to copy an item onto itself.
Expand Down Expand Up @@ -2860,6 +2861,19 @@ protected override void RemoveItem(string path, bool recurse)
return;
}

if (Context != null
&& Context.ExecutionContext.SessionState.PSVariable.Get(SpecialVariables.ProgressPreferenceVarPath.UserPath).Value is ActionPreference progressPreference
&& progressPreference == ActionPreference.Continue)
{
{
Task.Run(() =>
{
GetTotalFiles(path, recurse);
});
_removeStopwatch.Start();
}
}

#if UNIX
if (iscontainer)
{
Expand Down Expand Up @@ -2923,6 +2937,16 @@ protected override void RemoveItem(string path, bool recurse)
RemoveFileInfoItem((FileInfo)fsinfo, Force);
}
}

if (Stopping || _removedFiles == _totalFiles)
{
_removeStopwatch.Stop();
var progress = new ProgressRecord(REMOVE_FILE_ACTIVITY_ID, " ", " ")
{
RecordType = ProgressRecordType.Completed
};
WriteProgress(progress);
}
#endif
}
catch (IOException exception)
Expand Down Expand Up @@ -3057,6 +3081,8 @@ void WriteErrorHelper(Exception exception)

if (file != null)
{
long fileBytesSize = file.Length;

if (recurse)
{
// When recurse is specified we need to confirm each
Expand All @@ -3069,6 +3095,22 @@ void WriteErrorHelper(Exception exception)
// subitems without confirming with the user.
RemoveFileSystemItem(file, force);
}

if (_totalFiles > 0)
{
_removedFiles++;
_removedBytes += fileBytesSize;
double speed = _removedBytes / 1024 / 1024 / _removeStopwatch.Elapsed.TotalSeconds;
var progress = new ProgressRecord(
REMOVE_FILE_ACTIVITY_ID,
StringUtil.Format(FileSystemProviderStrings.RemovingLocalFileActivity, _removedFiles, _totalFiles),
StringUtil.Format(FileSystemProviderStrings.RemovingLocalBytesStatus, Utils.DisplayHumanReadableFileSize(_removedBytes), Utils.DisplayHumanReadableFileSize(_totalBytes), speed)
);
var percentComplete = (int)Math.Min(_removedBytes * 100 / _totalBytes, 100);
progress.PercentComplete = percentComplete;
progress.RecordType = ProgressRecordType.Processing;
WriteProgress(progress);
}
}
}

Expand Down Expand Up @@ -4884,6 +4926,10 @@ private bool PathIsReservedDeviceName(string destinationPath, string errorId)
private long _copiedBytes;
private readonly Stopwatch _copyStopwatch = new Stopwatch();

private long _removedBytes;
private long _removedFiles;
private readonly Stopwatch _removeStopwatch = new();

#endregion CopyItem

#endregion ContainerCmdletProvider members
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@
<data name="CopyingLocalBytesStatus" xml:space="preserve">
<value>{0} of {1} ({2:0.0} MB/s)</value>
</data>
<data name="RemovingLocalFileActivity" xml:space="preserve">
<value>Removed {0} of {1} files</value>
</data>
<data name="RemovingLocalBytesStatus" xml:space="preserve">
<value>{0} of {1} ({2:0.0} MB/s)</value>
</data>
<data name="JunctionAbsolutePath" xml:space="preserve">
<value>Creating a junction requires an absolute path for the target.</value>
</data>
Expand Down