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:
@@ -3115,16 +3115,19 @@ namespace Microsoft.PowerShell.Commands
|
|||||||
{
|
{
|
||||||
_removedFiles++;
|
_removedFiles++;
|
||||||
_removedBytes += fileBytesSize;
|
_removedBytes += fileBytesSize;
|
||||||
double speed = _removedBytes / 1024 / 1024 / _removeStopwatch.Elapsed.TotalSeconds;
|
if (_removeStopwatch.Elapsed.TotalSeconds > ProgressBarDurationThreshold)
|
||||||
var progress = new ProgressRecord(
|
{
|
||||||
REMOVE_FILE_ACTIVITY_ID,
|
double speed = _removedBytes / 1024 / 1024 / _removeStopwatch.Elapsed.TotalSeconds;
|
||||||
StringUtil.Format(FileSystemProviderStrings.RemovingLocalFileActivity, _removedFiles, _totalFiles),
|
var progress = new ProgressRecord(
|
||||||
StringUtil.Format(FileSystemProviderStrings.RemovingLocalBytesStatus, Utils.DisplayHumanReadableFileSize(_removedBytes), Utils.DisplayHumanReadableFileSize(_totalBytes), speed)
|
REMOVE_FILE_ACTIVITY_ID,
|
||||||
);
|
StringUtil.Format(FileSystemProviderStrings.RemovingLocalFileActivity, _removedFiles, _totalFiles),
|
||||||
var percentComplete = _totalBytes != 0 ? (int)Math.Min(_removedBytes * 100 / _totalBytes, 100) : 100;
|
StringUtil.Format(FileSystemProviderStrings.RemovingLocalBytesStatus, Utils.DisplayHumanReadableFileSize(_removedBytes), Utils.DisplayHumanReadableFileSize(_totalBytes), speed)
|
||||||
progress.PercentComplete = percentComplete;
|
);
|
||||||
progress.RecordType = ProgressRecordType.Processing;
|
var percentComplete = _totalBytes != 0 ? (int)Math.Min(_removedBytes * 100 / _totalBytes, 100) : 100;
|
||||||
WriteProgress(progress);
|
progress.PercentComplete = percentComplete;
|
||||||
|
progress.RecordType = ProgressRecordType.Processing;
|
||||||
|
WriteProgress(progress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3994,16 +3997,19 @@ namespace Microsoft.PowerShell.Commands
|
|||||||
{
|
{
|
||||||
_copiedFiles++;
|
_copiedFiles++;
|
||||||
_copiedBytes += file.Length;
|
_copiedBytes += file.Length;
|
||||||
double speed = (double)(_copiedBytes / 1024 / 1024) / _copyStopwatch.Elapsed.TotalSeconds;
|
if (_copyStopwatch.Elapsed.TotalSeconds > ProgressBarDurationThreshold)
|
||||||
var progress = new ProgressRecord(
|
{
|
||||||
COPY_FILE_ACTIVITY_ID,
|
double speed = (double)(_copiedBytes / 1024 / 1024) / _copyStopwatch.Elapsed.TotalSeconds;
|
||||||
StringUtil.Format(FileSystemProviderStrings.CopyingLocalFileActivity, _copiedFiles, _totalFiles),
|
var progress = new ProgressRecord(
|
||||||
StringUtil.Format(FileSystemProviderStrings.CopyingLocalBytesStatus, Utils.DisplayHumanReadableFileSize(_copiedBytes), Utils.DisplayHumanReadableFileSize(_totalBytes), speed)
|
COPY_FILE_ACTIVITY_ID,
|
||||||
);
|
StringUtil.Format(FileSystemProviderStrings.CopyingLocalFileActivity, _copiedFiles, _totalFiles),
|
||||||
var percentComplete = _totalBytes != 0 ? (int)Math.Min(_copiedBytes * 100 / _totalBytes, 100) : 100;
|
StringUtil.Format(FileSystemProviderStrings.CopyingLocalBytesStatus, Utils.DisplayHumanReadableFileSize(_copiedBytes), Utils.DisplayHumanReadableFileSize(_totalBytes), speed)
|
||||||
progress.PercentComplete = percentComplete;
|
);
|
||||||
progress.RecordType = ProgressRecordType.Processing;
|
var percentComplete = _totalBytes != 0 ? (int)Math.Min(_copiedBytes * 100 / _totalBytes, 100) : 100;
|
||||||
WriteProgress(progress);
|
progress.PercentComplete = percentComplete;
|
||||||
|
progress.RecordType = ProgressRecordType.Processing;
|
||||||
|
WriteProgress(progress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -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