aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager
diff options
context:
space:
mode:
authorRaphael <raphael@google.com>2011-11-30 22:51:08 -0800
committerRaphael <raphael@google.com>2011-11-30 22:51:08 -0800
commitd9b8f06adac48d40d7201d15d2396d193bc0e5e6 (patch)
tree7b83b9895799d7e151eef02ae268bcc21883dad0 /sdkmanager
parent27b2ac34506d7142e8b9fc5abe7aebcf1790e882 (diff)
downloadsdk-d9b8f06adac48d40d7201d15d2396d193bc0e5e6.zip
sdk-d9b8f06adac48d40d7201d15d2396d193bc0e5e6.tar.gz
sdk-d9b8f06adac48d40d7201d15d2396d193bc0e5e6.tar.bz2
SDK Manager: verbose print if unzip fails.
The core issue was that source packages were not properly zipped on the build server side, which made the unzip crash with an EOFException. This simply adds a better verbose message in case this happens again. It seems the Java ZipFile bug listed in there is fixed at least in the JVM I'm currently running (1.6 and 7) but anyway I added the extra safeguard code as documented in the reported bug (e.g. don't ask ZipFile to unzip more than the actual size of the entry.) Can't hurt to have it. Change-Id: Ib47530920474e320da69c35d9a695d931bed55c1
Diffstat (limited to 'sdkmanager')
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java
index ee442e1..934044f 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java
@@ -27,6 +27,7 @@ import com.android.sdklib.repository.RepoConstants;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
+import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -703,15 +704,26 @@ public class ArchiveInstaller {
}
FileOutputStream fos = null;
+ long remains = entry.getSize();
try {
fos = new FileOutputStream(destFile);
- int n;
+
+ // Java bug 4040920: do not rely on the input stream EOF and don't
+ // try to read more than the entry's size.
InputStream entryContent = zipFile.getInputStream(entry);
- while ((n = entryContent.read(buf)) != -1) {
+ int n;
+ while (remains > 0 &&
+ (n = entryContent.read(
+ buf, 0, (int) Math.min(remains, buf.length))) != -1) {
+ remains -= n;
if (n > 0) {
fos.write(buf, 0, n);
}
}
+ } catch (EOFException e) {
+ monitor.logError("Error uncompressing file %s. Size: %d bytes, Unwritten: %d bytes.",
+ entry.getName(), entry.getSize(), remains);
+ throw e;
} finally {
if (fos != null) {
fos.close();