Skip to content

Commit 989633a

Browse files
committed
remove file when tar failed
1 parent b466454 commit 989633a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,14 @@ public Void exec() throws NotFoundException {
125125
"Only one of host resource or tar input stream should be defined to perform the copy, not both");
126126
}
127127
// We compress the given path, call exec so that the stream is consumed and then close it our self
128-
Path toUpload;
128+
Path toUpload = null;
129129
try {
130130
toUpload = Files.createTempFile("docker-java", ".tar.gz");
131131
CompressArchiveUtil.tar(Paths.get(hostResource), toUpload, true, dirChildrenOnly);
132132
} catch (IOException createFileIOException) {
133+
if (toUpload != null) {
134+
toUpload.toFile().delete();
135+
}
133136
throw new DockerClientException("Unable to perform tar on host resource " + this.hostResource, createFileIOException);
134137
}
135138
try (InputStream uploadStream = Files.newInputStream(toUpload)) {

0 commit comments

Comments
 (0)