1
0
mirror of https://github.com/PowerShell/PowerShell synced 2025-10-06 00:22:59 +02:00

Delay progress bar in Copy-Item and Remove-Item cmdlets (#24013)

This commit is contained in:
SpyGod
2024-08-19 20:18:58 -07:00
committed by GitHub
parent 07f0798026
commit be59e5e80e

View File

@@ -3115,6 +3115,8 @@ namespace Microsoft.PowerShell.Commands
{
_removedFiles++;
_removedBytes += fileBytesSize;
if (_removeStopwatch.Elapsed.TotalSeconds > ProgressBarDurationThreshold)
{
double speed = _removedBytes / 1024 / 1024 / _removeStopwatch.Elapsed.TotalSeconds;
var progress = new ProgressRecord(
REMOVE_FILE_ACTIVITY_ID,
@@ -3128,6 +3130,7 @@ namespace Microsoft.PowerShell.Commands
}
}
}
}
// Check to see if the item has children
bool hasChildren = DirectoryInfoHasChildItems(directory);
@@ -3994,6 +3997,8 @@ namespace Microsoft.PowerShell.Commands
{
_copiedFiles++;
_copiedBytes += file.Length;
if (_copyStopwatch.Elapsed.TotalSeconds > ProgressBarDurationThreshold)
{
double speed = (double)(_copiedBytes / 1024 / 1024) / _copyStopwatch.Elapsed.TotalSeconds;
var progress = new ProgressRecord(
COPY_FILE_ACTIVITY_ID,
@@ -4006,6 +4011,7 @@ namespace Microsoft.PowerShell.Commands
WriteProgress(progress);
}
}
}
else
{
PerformCopyFileToRemoteSession(file, destinationPath, ps);
@@ -4945,6 +4951,7 @@ namespace Microsoft.PowerShell.Commands
private long _removedFiles;
private readonly Stopwatch _removeStopwatch = new();
private const double ProgressBarDurationThreshold = 2.0;
#endregion CopyItem
#endregion ContainerCmdletProvider members