|
1 | 1 | package com.github.dockerjava.core.dockerfile; |
2 | 2 |
|
3 | | -import java.io.File; |
4 | | -import java.io.IOException; |
5 | | -import java.io.InputStream; |
6 | | -import java.util.ArrayList; |
7 | | -import java.util.Collection; |
8 | | -import java.util.HashMap; |
9 | | -import java.util.List; |
10 | | -import java.util.Map; |
11 | | -import java.util.UUID; |
12 | | - |
13 | | -import org.apache.commons.io.FileUtils; |
14 | | -import org.apache.commons.io.FilenameUtils; |
15 | | -import org.apache.commons.io.filefilter.TrueFileFilter; |
16 | | - |
17 | 3 | import com.github.dockerjava.api.DockerClientException; |
18 | 4 | import com.github.dockerjava.core.CompressArchiveUtil; |
19 | 5 | import com.github.dockerjava.core.FilePathUtil; |
|
24 | 10 | import com.google.common.base.Objects; |
25 | 11 | import com.google.common.base.Optional; |
26 | 12 | import com.google.common.collect.Collections2; |
| 13 | +import org.apache.commons.io.FileUtils; |
| 14 | +import org.apache.commons.io.FilenameUtils; |
| 15 | +import org.apache.commons.io.IOUtils; |
| 16 | +import org.apache.commons.io.filefilter.TrueFileFilter; |
| 17 | + |
| 18 | +import java.io.File; |
| 19 | +import java.io.IOException; |
| 20 | +import java.io.InputStream; |
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.Collection; |
| 23 | +import java.util.HashMap; |
| 24 | +import java.util.List; |
| 25 | +import java.util.Map; |
| 26 | +import java.util.UUID; |
27 | 27 |
|
28 | 28 | /** |
29 | 29 | * Parse a Dockerfile. |
@@ -130,15 +130,29 @@ public InputStream buildDockerFolderTar() { |
130 | 130 |
|
131 | 131 | public InputStream buildDockerFolderTar(File directory) { |
132 | 132 |
|
133 | | - // ARCHIVE TAR |
134 | 133 | File dockerFolderTar = null; |
135 | 134 |
|
136 | 135 | try { |
137 | | - String archiveNameWithOutExtension = UUID.randomUUID().toString(); |
| 136 | + final String archiveNameWithOutExtension = UUID.randomUUID().toString(); |
138 | 137 |
|
139 | 138 | dockerFolderTar = CompressArchiveUtil.archiveTARFiles(directory, filesToAdd, |
140 | 139 | archiveNameWithOutExtension); |
141 | | - return FileUtils.openInputStream(dockerFolderTar); |
| 140 | + |
| 141 | + final InputStream tarInputStream = FileUtils.openInputStream(dockerFolderTar); |
| 142 | + final File tarFile = dockerFolderTar; |
| 143 | + |
| 144 | + return new InputStream() { |
| 145 | + @Override |
| 146 | + public int read() throws IOException { |
| 147 | + return tarInputStream.read(); |
| 148 | + } |
| 149 | + |
| 150 | + @Override |
| 151 | + public void close() throws IOException { |
| 152 | + IOUtils.closeQuietly(tarInputStream); |
| 153 | + FileUtils.deleteQuietly(tarFile); |
| 154 | + } |
| 155 | + }; |
142 | 156 |
|
143 | 157 | } catch (IOException ex) { |
144 | 158 | FileUtils.deleteQuietly(dockerFolderTar); |
|
0 commit comments