From b0b8eaef1ea0a6350cc596cd3cbfd44f4b00b7da Mon Sep 17 00:00:00 2001 From: Samuel Vasko Date: Wed, 5 Mar 2014 14:31:01 +0100 Subject: [PATCH] Error checking for 7z extraction --- scripts/build.ps1 | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 6a7891d..6c8094b 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -48,8 +48,8 @@ function Ensure-Exists ($item) { } function Ensure-Executable ($command) { - try { Get-Command $command -ErrorAction Stop > $null} - catch{ + try { Get-Command $command -ErrorAction Stop > $null } + catch { Write-Error "Missing $command! Ensure it is installed and on in the PATH" exit 1 } @@ -69,6 +69,14 @@ function Flatten-Directory ($name) { Remove-Item -Recurse "$($name)_moving" } +function Extract-Archive ($source, $target) { + Invoke-Expression "7z x -y -o$($target) $source" + if ($lastexitcode -ne 0) { + Write-Error "Extracting of $source failied" + } + Remove-Item $source +} + $ErrorActionPreference = "Stop" # Check for requirements @@ -87,8 +95,7 @@ foreach ($s in $sources) { Delete-Existing $s.name Invoke-WebRequest -Uri $s.url -OutFile $tempArchive -ErrorAction Stop - Invoke-Expression "7z x -y -o$($s.name) $tempArchive" - Remove-Item $tempArchive + Extract-Archive $tempArchive $s.name if ((Get-Childitem $s.name).Count -eq 1) { Flatten-Directory($s.name)