mirror of
https://github.com/PowerShell/PowerShell
synced 2025-10-06 16:42:47 +02:00
Delay progress bar in Copy-Item and Remove-Item cmdlets (#24013)
This commit is contained in:
@@ -3115,6 +3115,8 @@ namespace Microsoft.PowerShell.Commands
|
|||||||
{
|
{
|
||||||
_removedFiles++;
|
_removedFiles++;
|
||||||
_removedBytes += fileBytesSize;
|
_removedBytes += fileBytesSize;
|
||||||
|
if (_removeStopwatch.Elapsed.TotalSeconds > ProgressBarDurationThreshold)
|
||||||
|
{
|
||||||
double speed = _removedBytes / 1024 / 1024 / _removeStopwatch.Elapsed.TotalSeconds;
|
double speed = _removedBytes / 1024 / 1024 / _removeStopwatch.Elapsed.TotalSeconds;
|
||||||
var progress = new ProgressRecord(
|
var progress = new ProgressRecord(
|
||||||
REMOVE_FILE_ACTIVITY_ID,
|
REMOVE_FILE_ACTIVITY_ID,
|
||||||
@@ -3128,6 +3130,7 @@ namespace Microsoft.PowerShell.Commands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check to see if the item has children
|
// Check to see if the item has children
|
||||||
bool hasChildren = DirectoryInfoHasChildItems(directory);
|
bool hasChildren = DirectoryInfoHasChildItems(directory);
|
||||||
@@ -3994,6 +3997,8 @@ namespace Microsoft.PowerShell.Commands
|
|||||||
{
|
{
|
||||||
_copiedFiles++;
|
_copiedFiles++;
|
||||||
_copiedBytes += file.Length;
|
_copiedBytes += file.Length;
|
||||||
|
if (_copyStopwatch.Elapsed.TotalSeconds > ProgressBarDurationThreshold)
|
||||||
|
{
|
||||||
double speed = (double)(_copiedBytes / 1024 / 1024) / _copyStopwatch.Elapsed.TotalSeconds;
|
double speed = (double)(_copiedBytes / 1024 / 1024) / _copyStopwatch.Elapsed.TotalSeconds;
|
||||||
var progress = new ProgressRecord(
|
var progress = new ProgressRecord(
|
||||||
COPY_FILE_ACTIVITY_ID,
|
COPY_FILE_ACTIVITY_ID,
|
||||||
@@ -4006,6 +4011,7 @@ namespace Microsoft.PowerShell.Commands
|
|||||||
WriteProgress(progress);
|
WriteProgress(progress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PerformCopyFileToRemoteSession(file, destinationPath, ps);
|
PerformCopyFileToRemoteSession(file, destinationPath, ps);
|
||||||
@@ -4945,6 +4951,7 @@ namespace Microsoft.PowerShell.Commands
|
|||||||
private long _removedFiles;
|
private long _removedFiles;
|
||||||
private readonly Stopwatch _removeStopwatch = new();
|
private readonly Stopwatch _removeStopwatch = new();
|
||||||
|
|
||||||
|
private const double ProgressBarDurationThreshold = 2.0;
|
||||||
#endregion CopyItem
|
#endregion CopyItem
|
||||||
|
|
||||||
#endregion ContainerCmdletProvider members
|
#endregion ContainerCmdletProvider members
|
||||||
|
Reference in New Issue
Block a user