Skip to content

Fix progress calculation on Remove-Item - #23869

Merged
Dongbo Wang (daxian-dbw) merged 1 commit into
PowerShell:masterfrom
jborean93:remove-progress
Jul 1, 2024
Merged

Dongbo Wang (daxian-dbw) merged 1 commit into
PowerShell:masterfrom
jborean93:remove-progress

Conversation

@jborean93

Copy link
Copy Markdown
Collaborator

PR Summary

Fix the percentage completion calculation for Remove-Item when deleting a directory or file that have no size. As the size calculation is done in a background thread this may or may not happen due to a race condition of when it is calculated.

PR Context

Fixes: #23868

I can't write a test for this as the _totalFiles and _totalBytes calculation is done in a background thread and will most likely run after the progress check is done in the main thread. The changes are consistent in what is done in #19038 for a similar problem.

PR Checklist

@iSazonov

Copy link
Copy Markdown
Collaborator

As for new test, we could create new test hook - if the hook is on we save Task.Run() in the test hook and wait the task later in remove item code. This makes the code sync

@jborean93

Copy link
Copy Markdown
Collaborator Author

I have reservations about tests that alter behavior during execution. This approach can lead to discrepancies, as seen in this issue, where the behavior observed during testing differs from that in the released package. Additionally, it increases the complexity of the code. I will defer to the Working Group on this matter and leave the decision, and work if they want it, to them.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Review - Needed The PR is being reviewed label Jun 10, 2024
@daxian-dbw Dongbo Wang (daxian-dbw) added CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log and removed Review - Needed The PR is being reviewed labels Jul 1, 2024
Fix the percentage completion calculation for Remove-Item when deleting
a directory or file that have no size. As the size calculation is done
in a background thread this may or may not happen due to a race
condition of when it is calculated.
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 720f145 into PowerShell:master Jul 1, 2024
@microsoft-github-policy-service

microsoft-github-policy-service Bot commented Jul 1, 2024 •

Copy link
Copy Markdown
Contributor

📣 Hey Jordan Borean (@jborean93), how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

@jborean93
Jordan Borean (jborean93) deleted the remove-progress branch July 2, 2024 05:42
Chris Dent (chrisdent-de) pushed a commit to chrisdent-de/PowerShell that referenced this pull request Sep 12, 2024
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove-Item throws "Attempted to divide by zero" on PS 7.5.0-preview.3

5 participants