Skip to content

Commit 5b4c957

Browse files
committed
Merge branch 'banadiga-create-temp-files-in-atemp-dorectory'
2 parents 1f93f08 + 2570b28 commit 5b4c957

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
## UNRELEASED
55
### Fixed
66
- Fixed regression in 1.4.3 when using Docker Compose on Windows ([\#439](https://github.com/testcontainers/testcontainers-java/issues/439))
7+
- Fixed local Docker Compose executable name resolution on Windows (#416)
8+
- Fixed TAR composition on Windows (#444)
9+
- Allowing `addExposedPort` to be used after ports have been specified with `withExposedPorts` (#453)
10+
- Stopping creation of temporary directory prior to creating temporary file (#443)
11+
- Ensure that temp files are created in a temp directory (#423)
712

813
### Changed
914
- Make Network instances reusable (i.e. work with `@ClassRule`) ([\#469](https://github.com/testcontainers/testcontainers-java/issues/469))

core/src/main/java/org/testcontainers/utility/MountableFile.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
package org.testcontainers.utility;
22

3-
import com.google.common.base.Charsets;
4-
import lombok.Getter;
5-
import lombok.RequiredArgsConstructor;
6-
import lombok.extern.slf4j.Slf4j;
7-
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
8-
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
9-
import org.apache.commons.lang.SystemUtils;
10-
import org.jetbrains.annotations.NotNull;
11-
import org.testcontainers.images.builder.Transferable;
3+
import static lombok.AccessLevel.PACKAGE;
4+
import static org.testcontainers.utility.PathUtils.recursiveDeleteDir;
125

6+
import com.google.common.base.Charsets;
137
import java.io.File;
148
import java.io.IOException;
159
import java.io.InputStream;
@@ -25,9 +19,14 @@
2519
import java.util.Set;
2620
import java.util.jar.JarEntry;
2721
import java.util.jar.JarFile;
28-
29-
import static lombok.AccessLevel.PACKAGE;
30-
import static org.testcontainers.utility.PathUtils.recursiveDeleteDir;
22+
import lombok.Getter;
23+
import lombok.RequiredArgsConstructor;
24+
import lombok.extern.slf4j.Slf4j;
25+
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
26+
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
27+
import org.apache.commons.lang.SystemUtils;
28+
import org.jetbrains.annotations.NotNull;
29+
import org.testcontainers.images.builder.Transferable;
3130

3231
/**
3332
* An abstraction over files and classpath resources aimed at encapsulating all the complexity of generating
@@ -37,6 +36,8 @@
3736
@Slf4j
3837
public class MountableFile implements Transferable {
3938

39+
private static final String TESTCONTAINERS_TMP_DIR_PREFIX = ".testcontainers-tmp-";
40+
private static final String OS_MAC_TMP_DIR = "/tmp";
4041
private static final int BASE_FILE_MODE = 0100000;
4142
private static final int BASE_DIR_MODE = 0040000;
4243

@@ -205,7 +206,7 @@ private String getResourcePath() {
205206
* @return the path of the temporary file/directory
206207
*/
207208
private String extractClassPathResourceToTempLocation(final String hostPath) {
208-
File tmpLocation = new File(".testcontainers-tmp-" + Base58.randomString(5));
209+
File tmpLocation = createTempDirectory();
209210
//noinspection ResultOfMethodCallIgnored
210211
tmpLocation.delete();
211212

@@ -236,6 +237,17 @@ private String extractClassPathResourceToTempLocation(final String hostPath) {
236237
return tmpLocation.getAbsolutePath();
237238
}
238239

240+
private File createTempDirectory() {
241+
try {
242+
if (SystemUtils.IS_OS_MAC) {
243+
return Files.createTempDirectory(Paths.get(OS_MAC_TMP_DIR), TESTCONTAINERS_TMP_DIR_PREFIX).toFile();
244+
}
245+
return Files.createTempDirectory(TESTCONTAINERS_TMP_DIR_PREFIX).toFile();
246+
} catch (IOException e) {
247+
return new File(TESTCONTAINERS_TMP_DIR_PREFIX + Base58.randomString(5));
248+
}
249+
}
250+
239251
@SuppressWarnings("ResultOfMethodCallIgnored")
240252
private void copyFromJarToLocation(final JarFile jarFile,
241253
final JarEntry entry,
@@ -356,4 +368,4 @@ private int getModeValue(final Path path) {
356368
int result = Files.isDirectory(path) ? BASE_DIR_MODE : BASE_FILE_MODE;
357369
return result | this.forcedFileMode;
358370
}
359-
}
371+
}

0 commit comments

Comments
 (0)