mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix progress calculation divide by zero in Copy-Item (#19038)
This commit is contained in:
@@ -3938,7 +3938,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
StringUtil.Format(FileSystemProviderStrings.CopyingLocalFileActivity, _copiedFiles, _totalFiles),
|
||||
StringUtil.Format(FileSystemProviderStrings.CopyingLocalBytesStatus, Utils.DisplayHumanReadableFileSize(_copiedBytes), Utils.DisplayHumanReadableFileSize(_totalBytes), speed)
|
||||
);
|
||||
var percentComplete = (int)Math.Min(_copiedBytes * 100 / _totalBytes, 100);
|
||||
var percentComplete = _totalBytes != 0 ? (int)Math.Min(_copiedBytes * 100 / _totalBytes, 100) : 100;
|
||||
progress.PercentComplete = percentComplete;
|
||||
progress.RecordType = ProgressRecordType.Processing;
|
||||
WriteProgress(progress);
|
||||
|
||||
@@ -317,6 +317,12 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {
|
||||
Remove-Item -Path $testPath -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
It "Copy-Item can copy 0 byte length file" {
|
||||
$zeroLengthFile = New-Item -Path (Join-Path $TestDrive "zeroLengthFile.txt") -ItemType File -Force
|
||||
Copy-Item -Path $zeroLengthFile -Destination "$TestDrive\zeroLengthFile2.txt" -Force
|
||||
"$TestDrive\zeroLengthFile2.txt" | Should -Exist
|
||||
}
|
||||
}
|
||||
|
||||
Context "Validate behavior when access is denied" {
|
||||
|
||||
Reference in New Issue
Block a user