Added retry when unzip fail because of AV#1822
Added retry when unzip fail because of AV#1822r15ch13 merged 5 commits intoScoopInstaller:masterfrom
Conversation
Trend AV analyses and lock zip files just after download. I have added 2 retries in case of this event.
|
What happens when you install 7zip? Does it still not work? |
|
Can you try the following? Add this function to core.ps1 function isFileLocked([string]$path) {
$file = New-Object System.IO.FileInfo $path
if((Test-Path -Path $path) -eq $false) {
return $false
}
try {
$stream = $file.Open([System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None)
if ($stream) {
$stream.Close()
}
return $false
} catch {
# file is locked by a process.
return $true
}
}And change unzip() to: function unzip($path,$to) {
if(!(test-path $path)) { abort "can't find $path to unzip"}
try { add-type -assembly "System.IO.Compression.FileSystem" -ea stop }
catch { unzip_old $path $to; return } # for .net earlier than 4.5
$retries = 0
while($retries -le 10) {
if($retries -eq 10) {
abort "Unzip failed: Too many retries!"
}
if(isFileLocked $path) {
write-host "Waiting for $path to be unlocked by another process... ($retries/10)"
$retries++
Start-Sleep -s 2
} else {
break
}
}
try {
[io.compression.zipfile]::extracttodirectory($path,$to)
} catch [system.io.pathtoolongexception] {
# try to fall back to 7zip if path is too long
if(7zip_installed) {
extract_7zip $path $to $false
return
} else {
abort "Unzip failed: Windows can't handle the long paths in this zip file.`nRun 'scoop install 7zip' and try again."
}
} catch {
abort "Unzip failed: $_"
}
} |
|
Aww... still getting the error for very big files with both my code and your's. |
|
Currently trying with 30 retries |
|
Well 30 was not enough, he blocked on a different file, retrying with 60 retries. |
|
Well seems like scoop reaches a sort of timout and won't proceed further. I'm getting the same result after the same time even while setting numbers like 1000 - 2000. |
|
OK! It worked, instead of default unzip, I used the "extract_7zip $path $to $false" by default. Seems like 7zip can deal with the waiting. |
7zip can deal with an antivirus locking the file but extracttodirectory can't.
|
Thanks ^^ |
|
@r15ch13: this is ready to merge, yes? |
Trend AV analyses and lock zip files just after download. I have added 2 retries in case of this event.
At work I can't change antivirus settings so I have no other choice than to modify the unzip function.