Skip to content

Commit 9a797ae

Browse files
authored
Merge pull request docker-java#1003 from fengxx/bugfix/mutable_cp_file_stream
tarInputStream was changed during exec and rerun the method will thro…
2 parents e9c036b + 9a81d92 commit 9a797ae

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/main/java/com/github/dockerjava/core/command/CopyArchiveToContainerCmdImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public Void exec() throws NotFoundException {
143143
} catch (IOException e) {
144144
throw new DockerClientException("Unable to read temp file " + toUpload.toFile().getAbsolutePath(), e);
145145
} finally {
146+
this.tarInputStream = null;
146147
// remove tmp docker-javaxxx.tar.gz
147148
toUpload.toFile().delete();
148149
}

src/test/java/com/github/dockerjava/cmd/CopyArchiveToContainerCmdIT.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.dockerjava.cmd;
22

3+
import com.github.dockerjava.api.command.CopyArchiveToContainerCmd;
34
import com.github.dockerjava.api.command.CreateContainerResponse;
45
import com.github.dockerjava.api.exception.NotFoundException;
56
import com.github.dockerjava.core.command.WaitContainerResultCallback;
@@ -47,6 +48,17 @@ public void copyStreamToContainer() throws Exception {
4748
assertFileCopied(container);
4849
}
4950

51+
@Test
52+
public void copyStreamToContainerTwice() throws Exception {
53+
CreateContainerResponse container = prepareContainerForCopy("rerun");
54+
CopyArchiveToContainerCmd copyArchiveToContainerCmd=dockerRule.getClient().copyArchiveToContainerCmd(container.getId())
55+
.withHostResource("src/test/resources/testReadFile");
56+
copyArchiveToContainerCmd.exec();
57+
assertFileCopied(container);
58+
//run again to make sure no DockerClientException
59+
copyArchiveToContainerCmd.exec();
60+
}
61+
5062
private CreateContainerResponse prepareContainerForCopy(String method) {
5163
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox")
5264
.withName("docker-java-itest-copyToContainer" + method + dockerRule.getKind())

0 commit comments

Comments
 (0)