From fffa78e528fbefba7a863822d7fa8bb24885b99b Mon Sep 17 00:00:00 2001 From: Marco Vermeulen Date: Sun, 21 Oct 2012 18:47:20 +0100 Subject: [PATCH] Deal gracefully with corrupt archives when installing/reinstalling. --- .../cucumber/gvm/install_candidate.feature | 8 ++++++++ .../resources/gvm/installation_steps.groovy | 16 ++++++++++++++++ srv/scripts/gvm | 19 ++++++++++++++++--- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/test/cucumber/gvm/install_candidate.feature b/src/test/cucumber/gvm/install_candidate.feature index 4323aa27..5c13fded 100644 --- a/src/test/cucumber/gvm/install_candidate.feature +++ b/src/test/cucumber/gvm/install_candidate.feature @@ -19,3 +19,11 @@ Feature: Install Candidate Given the candidate "grails" version "1.3.9" is already installed When I enter "gvm install grails 1.3.9" Then I see "Stop! grails 1.3.9 is already installed." + + Scenario: Abort installation on download of a corrupt Candidate archive + Given the archive for candidate "grails" version "1.3.6" is corrupt + When I enter "gvm install grails 1.3.6" + Then I see "Stop! The download failed! Please try again." + And the candidate "grails" version "1.3.6" is not installed + And the archive for candidate "grails" version "1.3.6" is removed + diff --git a/src/test/resources/gvm/installation_steps.groovy b/src/test/resources/gvm/installation_steps.groovy index 8c0662a7..412ef5ee 100644 --- a/src/test/resources/gvm/installation_steps.groovy +++ b/src/test/resources/gvm/installation_steps.groovy @@ -1,5 +1,6 @@ import static cucumber.runtime.groovy.EN.* import cucumber.runtime.PendingException +import java.util.zip.* scriptPath = 'srv/scripts' gvmDir = new File(System.getenv('GVM_DIR')) @@ -23,3 +24,18 @@ When(~'^the candidate "([^"]*)" version "([^"]*)" is already installed$') { Stri def result = "${proc.in.text}" assert result.contains("Done installing!") } + +When(~'^the archive for candidate "([^"]*)" version "([^"]*)" is corrupt$') { String candidate, String version -> + try { + new ZipFile(new File("src/test/resources/${candidate}-${version}.zip")) + assert false, "Archive was not corrupt!" + + } catch (ZipException ze){ + //expected behaviour + } +} + +Then(~'^the archive for candidate "([^"]*)" version "([^"]*)" is removed$') { String candidate, String version -> + def archive = new File("${gvmDir}/archives/${candidate}-${version}.zip") + assert ! archive.exists() +} diff --git a/srv/scripts/gvm b/srv/scripts/gvm index 776391f7..e269bba3 100755 --- a/srv/scripts/gvm +++ b/srv/scripts/gvm @@ -91,15 +91,28 @@ function download { echo "Downloading: $CANDIDATE $VERSION" echo "" DOWNLOAD_URL="$GVM_SERVICE/download/$CANDIDATE/$VERSION?platform=$PLATFORM" - curl -L "$DOWNLOAD_URL" > "$GVM_DIR/archives/$CANDIDATE-$VERSION.zip" + ZIP_ARCHIVE="$GVM_DIR/archives/$CANDIDATE-$VERSION.zip" + curl -L "$DOWNLOAD_URL" > "$ZIP_ARCHIVE" + validate_zip "$ZIP_ARCHIVE" else echo "" - echo "Found a previously downloaded $CANDIDATE $VERSION archive." - echo "Not downloading it again..." + echo "Found a previously downloaded $CANDIDATE $VERSION archive. Not downloading it again..." + validate_zip "$GVM_DIR/archives/$CANDIDATE-$VERSION.zip" fi echo "" } +function validate_zip { + ZIP_ARCHIVE="$1" + ZIP_OK=$(zip -T "$ZIP_ARCHIVE" | grep 'OK') + if [ -z "$ZIP_OK" ]; then + rm "$ZIP_ARCHIVE" + echo "" + echo "Stop! The archive was corrupt and has been removed! Please try installing again." + exit 0 + fi +} + function server_down { echo "------------------------------------------" echo " This is serious! Service is down! "