From 6ed7d13594dca7db3f4fd812b31f543d348582d6 Mon Sep 17 00:00:00 2001 From: Julian Noble Date: Mon, 25 Aug 2025 00:10:24 +1000 Subject: [PATCH] getzig add powershell GC (garbage collection) calls to fix intermittent locking problem after zip extraction --- bin/getzig.cmd | 22 +++++++++++++++++----- src/scriptapps/getzig.ps1 | 22 +++++++++++++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/bin/getzig.cmd b/bin/getzig.cmd index dc616247..3c94068d 100644 --- a/bin/getzig.cmd +++ b/bin/getzig.cmd @@ -944,6 +944,11 @@ if ($mirrors_response.StatusCode -eq 200) { write-host "host_list: $host_list" $automation_name = "punkshell+julian@precisium.com.au_target_by_latency" + + #test-netconnection progressbar seems not-so-well-behaved (prog bar lingers) + #test-netconnection a function not cmdlet? Seems to need setting at global level + $OriginalProgressPreference = $Global:ProgressPreference + $Global:ProgressPreference = 'SilentlyContinue' #temporary dev download source $ihost = "10.30.30.107" $imirror = "http://10.30.30.107/jn/punkbin/raw/branch/master/win64/tools" @@ -954,9 +959,9 @@ if ($mirrors_response.StatusCode -eq 200) { $dict_mirrors[$ihost]["latency"] = 1 $dict_mirrors[$ihost]["uri"] = $imirror } - - $trace = test-netconnection gitea1.intx.com.au -Hops 6 -TraceRoute -ErrorAction Ignore + $Global:ProgressPreference = $OriginalProgressPreference + if ((${trace}.PingSucceeded) -and (${trace}.TraceRoute.Count -lt 5)) { $dict_mirrors["gitea1.intx.com.au"]["latency"] = 2 #short-circuit for hosts very near gitea1.intx.com.au @@ -1065,15 +1070,22 @@ if ($mirrors_response.StatusCode -eq 200) { Write-Host "Signature OK - extracting archive ..." #Expand-Archive -path $outfile -DestinationPath $toolsfolder -Force #This is *insanely* (many minutes vs seconds) slow on powershell 5 at least - we get a progress meter, but it's too high a price to pay. + # ------------------------------------- Add-Type -Assembly "System.IO.Compression.Filesystem" - [System.IO.Compression.Zipfile]::ExtractToDirectory($releasearchive,$toolsfolder) + [System.IO.Compression.Zipfile]::ExtractToDirectory($outfile, $toolsfolder) Write-Host " - archive extracted." - + #We *intermittently* get permission errors when trying to rename the resulting folder (possibly also if we try to delete the zip file immediately) + #There seems to be some sort of lock held after ExtractToDirectory (possibly AV related) + #https://stackoverflow.com/questions/74582293/file-lock-issues-on-zip-file-after-io-compression-zipfileextracttodirectory + [GC]::Collect() + [GC]::WaitForPendingFinalizers() + # ------------------------------------- #Remove-Item -Path "$outfile" $zip_rootname = [System.IO.Path]::GetFileNameWithoutExtension($releasearchive) #Rename-Item -Path - write-host "zip_rootname: $zip_rootname" + #write-host "zip_rootname: $zip_rootname" + write-host "moving $(Join-Path -Path $toolsfolder -ChildPath $zip_rootname) to ${zigfolder}" Rename-Item -Path $(Join-Path -Path $toolsfolder -ChildPath $zip_rootname) -NewName $zigfolder Write-Host "Zig installed in ${zigfolder}" $zigexe = Join-Path $zigfolder -ChildPath "zig.exe" diff --git a/src/scriptapps/getzig.ps1 b/src/scriptapps/getzig.ps1 index ddd90085..5d28029f 100644 --- a/src/scriptapps/getzig.ps1 +++ b/src/scriptapps/getzig.ps1 @@ -110,6 +110,11 @@ if ($mirrors_response.StatusCode -eq 200) { write-host "host_list: $host_list" $automation_name = "punkshell+julian@precisium.com.au_target_by_latency" + + #test-netconnection progressbar seems not-so-well-behaved (prog bar lingers) + #test-netconnection a function not cmdlet? Seems to need setting at global level + $OriginalProgressPreference = $Global:ProgressPreference + $Global:ProgressPreference = 'SilentlyContinue' #temporary dev download source $ihost = "10.30.30.107" $imirror = "http://10.30.30.107/jn/punkbin/raw/branch/master/win64/tools" @@ -120,9 +125,9 @@ if ($mirrors_response.StatusCode -eq 200) { $dict_mirrors[$ihost]["latency"] = 1 $dict_mirrors[$ihost]["uri"] = $imirror } - - $trace = test-netconnection gitea1.intx.com.au -Hops 6 -TraceRoute -ErrorAction Ignore + $Global:ProgressPreference = $OriginalProgressPreference + if ((${trace}.PingSucceeded) -and (${trace}.TraceRoute.Count -lt 5)) { $dict_mirrors["gitea1.intx.com.au"]["latency"] = 2 #short-circuit for hosts very near gitea1.intx.com.au @@ -231,15 +236,22 @@ if ($mirrors_response.StatusCode -eq 200) { Write-Host "Signature OK - extracting archive ..." #Expand-Archive -path $outfile -DestinationPath $toolsfolder -Force #This is *insanely* (many minutes vs seconds) slow on powershell 5 at least - we get a progress meter, but it's too high a price to pay. + # ------------------------------------- Add-Type -Assembly "System.IO.Compression.Filesystem" - [System.IO.Compression.Zipfile]::ExtractToDirectory($releasearchive,$toolsfolder) + [System.IO.Compression.Zipfile]::ExtractToDirectory($outfile, $toolsfolder) Write-Host " - archive extracted." - + #We *intermittently* get permission errors when trying to rename the resulting folder (possibly also if we try to delete the zip file immediately) + #There seems to be some sort of lock held after ExtractToDirectory (possibly AV related) + #https://stackoverflow.com/questions/74582293/file-lock-issues-on-zip-file-after-io-compression-zipfileextracttodirectory + [GC]::Collect() + [GC]::WaitForPendingFinalizers() + # ------------------------------------- #Remove-Item -Path "$outfile" $zip_rootname = [System.IO.Path]::GetFileNameWithoutExtension($releasearchive) #Rename-Item -Path - write-host "zip_rootname: $zip_rootname" + #write-host "zip_rootname: $zip_rootname" + write-host "moving $(Join-Path -Path $toolsfolder -ChildPath $zip_rootname) to ${zigfolder}" Rename-Item -Path $(Join-Path -Path $toolsfolder -ChildPath $zip_rootname) -NewName $zigfolder Write-Host "Zig installed in ${zigfolder}" $zigexe = Join-Path $zigfolder -ChildPath "zig.exe"