PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
475 stars 90 forks source link

Make delete more robust (fix #1662) #1667

Open o-l-a-v opened 5 days ago

o-l-a-v commented 5 days ago

PR Summary

Make delete more robust by trying multiple times before failing, to fix #1662.

PR Context

In #1662 I experienced that PSResourceGet would fail to install modules because antimalware realtime scanners added file handles on files inside %TEMP% that were to be deleted.

I read here https://stackoverflow.com/a/329502/9874541 that trying multiple times is a common approach for scenarios like these.

I then tried adapting the existing code to try multiple times on the step that sometimes failed.

I tried the code by building both net472 and netstandard2.0, and I could no longer reproduce #1662.

PR Checklist

o-l-a-v commented 3 days ago

I'm no C# expert, I've tried my best to make the delete directory function more robust by trying multiple times. Source of inspiration:

I've also tried to read up on the best way to wait a little between attempts. It's my understanding from what I've read that if function is not async, Thread.Sleep() is fine.