Skip to content

Commit

Permalink
Error on empty zips and follow redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
yamogi committed Sep 28, 2016
1 parent 85cf3de commit 791b0ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -37,17 +37,26 @@ Set<String> download(InputStream zippedInputstream) throws IOException {
private Set<String> downloadZipInputstream(ZipInputStream zis) throws IOException {
Set<String> addonFolders = new HashSet<>();
byte[] buffer = new byte[DOWNLOAD_BUFFER_SIZE];

boolean emptyZip = true;

ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
if (ze.isDirectory()) {
continue;
}
emptyZip = false;

String fileName = ze.getName();
int index = fileName.indexOf('/');
addonFolders.add(fileName.substring(0, index));

writeFile(zis, buffer, fileName);
}

if (emptyZip) {
throw new IOException("Got an empty zip file.");
}
return addonFolders;
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/bitbucket/keiki/jcurse/io/CurseImpl.java
Expand Up @@ -70,7 +70,12 @@ protected Set<String> downloadAndExtract(String downloadUrl) {
URLConnection connection = website.openConnection();
connection.setRequestProperty("User-Agent", USER_AGENT);

return folderHandler.download(connection.getInputStream());
String location = connection.getHeaderField("Location");
if (location == null) {
return folderHandler.download(connection.getInputStream());
} else {
return downloadAndExtract(location);
}
} catch(IOException e) {
throw new BusinessException("Problems reading data from Curse.", e);
}
Expand Down

0 comments on commit 791b0ba

Please sign in to comment.