Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Grunberg2016-12-07 14:23:15 -0500
committerJeff Johnston2016-12-07 16:22:11 -0500
commit0a7e7b8bb43224a229d8858d974281c22bc8d622 (patch)
tree2623c571ed638ef1c5f18f6e87507feb35ccb0c8
parentf507daa49138b674635d0469355355e1122177ed (diff)
downloadorg.eclipse.linuxtools-stable-5.2.tar.gz
org.eclipse.linuxtools-stable-5.2.tar.xz
org.eclipse.linuxtools-stable-5.2.zip
Bug 508858: Pass a blocking InputStream to the TarArchiveInputStream.v5.2.0astable-5.2
The input stream returned from copyContainer may be passing back available bytes which may not default to be 0. In this case, the tar input stream may be reading a header record and treat this incomplete record as EOF. Also fixed buffering to only write out what was read (number of bytes). Change-Id: Icbab8dc460eb613acf6e12cd2f5aba192c52e774 Reviewed-on: https://git.eclipse.org/r/86667 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CopyFromContainerCommandHandler.java42
1 files changed, 34 insertions, 8 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CopyFromContainerCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CopyFromContainerCommandHandler.java
index 9a28890bd9..a6ad0806a3 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CopyFromContainerCommandHandler.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CopyFromContainerCommandHandler.java
@@ -13,6 +13,7 @@ package org.eclipse.linuxtools.internal.docker.ui.commands;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.List;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
@@ -109,10 +110,17 @@ public class CopyFromContainerCommandHandler extends AbstractHandler {
COPY_FROM_CONTAINER_JOB_SUBTASK,
proxy.getFullPath()));
monitor.worked(1);
+ InputStream in = ((DockerConnection) connection)
+ .copyContainer(container.id(),
+ proxy.getLink());
+ /*
+ * The input stream from copyContainer might be
+ * incomplete or non-blocking so we should wrap it
+ * in a stream that is guaranteed to block until
+ * data is available.
+ */
TarArchiveInputStream k = new TarArchiveInputStream(
- ((DockerConnection) connection)
- .copyContainer(container.id(),
- proxy.getLink()));
+ new BlockingInputStream(in));
TarArchiveEntry te = null;
while ((te = k.getNextTarEntry()) != null) {
long size = te.getSize();
@@ -126,17 +134,19 @@ public class CopyFromContainerCommandHandler extends AbstractHandler {
f.createNewFile();
}
FileOutputStream os = new FileOutputStream(f);
- if (size > 4096)
- size = 4096;
- byte[] barray = new byte[(int) size];
- while (k.read(barray) > -1) {
+ int bufferSize = ((int) size > 4096 ? 4096
+ : (int) size);
+ byte[] barray = new byte[bufferSize];
+ int result = -1;
+ while ((result = k.read(barray, 0,
+ bufferSize)) > -1) {
if (monitor.isCanceled()) {
monitor.done();
k.close();
os.close();
return Status.CANCEL_STATUS;
}
- os.write(barray);
+ os.write(barray, 0, result);
}
os.close();
}
@@ -172,4 +182,20 @@ public class CopyFromContainerCommandHandler extends AbstractHandler {
}
+ /**
+ * A blocking input stream that waits until data is available.
+ */
+ public class BlockingInputStream extends InputStream {
+ private InputStream in;
+
+ public BlockingInputStream(InputStream in) {
+ this.in = in;
+ }
+
+ @Override
+ public int read() throws IOException {
+ return in.read();
+ }
+ }
+
}

Back to the top