mirror of
https://github.com/sdkman/sdkman-cli.git
synced 2026-02-01 02:03:18 -05:00
Deal gracefully with corrupt archives when installing/reinstalling.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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! "
|
||||
|
||||
Reference in New Issue
Block a user