I changed the extraction code to extract files one by one and check for the existence of the file before trying to extract. Can’t have a process lock a file that doesn’t can we? Well apparently we can…
$archive = [System.IO.Compression.ZipFile]::OpenRead($zipFile)
foreach ($file in $archive.Entries) {
$destinationFileName = [System.IO.Path]::Combine($destination, $file.FullName)
$destinationFilePath = [System.IO.Path]::GetDirectoryName($destinationFileName)
[System.IO.Directory]::CreateDirectory($destinationFilePath)
if (Test-Path $destinationFileName) {
}
else {
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($file, $destinationFileName, $false)
}
}
So this resulted in:
Exception calling "ExtractToFile" with "3" argument(s): "The process cannot
Error 12:20:25
access the file 'D:\Octopus Tentacle\Applications\UAT\Playup.Api\0.0.164-fb-bfe
Error 12:20:25
d40d\website\approot\bin\NewRelicAgent_x64_3.9.146.0.msi' because it is being
Error 12:20:25
used by another process."
Error 12:20:25
At D:\Octopus
Error 12:20:25
Tentacle\Applications\UAT\Playup.Api\0.0.164-fb-bfed40d\predeploy.ps1:28 char:4
Error 12:20:25
+ [System.IO.Compression.ZipFileExtensions]::ExtractToFile($file,
Error 12:20:25
$destinationF ...
Error 12:20:25
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error 12:20:25
~~~~~~~~~~~~
Error 12:20:25
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE
Error 12:20:25
xception
Error 12:20:25
+ FullyQualifiedErrorId : IOException
Fatal 12:20:25
PowerShell script returned a non-zero exit code: 1
All i can say is WTF!?