From 1d977acc36a79d16578e753c6415c97eeca01fa3 Mon Sep 17 00:00:00 2001 From: Ihor Banadiga Date: Fri, 1 Sep 2017 15:12:21 +0300 Subject: [PATCH 1/4] Create temp files in a temp directory --- .../org/testcontainers/utility/MountableFile.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/testcontainers/utility/MountableFile.java b/core/src/main/java/org/testcontainers/utility/MountableFile.java index 06d08c2996d..2c6596f10c9 100644 --- a/core/src/main/java/org/testcontainers/utility/MountableFile.java +++ b/core/src/main/java/org/testcontainers/utility/MountableFile.java @@ -33,6 +33,8 @@ @Slf4j public class MountableFile implements Transferable { + private static final String TESTCONTAINERS_TMP_DIR_PREFIX = ".testcontainers-tmp-"; + private final String path; @Getter(lazy = true) @@ -163,7 +165,7 @@ private String getResourcePath() { * @return the path of the temporary file/directory */ private String extractClassPathResourceToTempLocation(final String hostPath) { - File tmpLocation = new File(".testcontainers-tmp-" + Base58.randomString(5)); + File tmpLocation = createTempDirectory(); //noinspection ResultOfMethodCallIgnored tmpLocation.delete(); @@ -194,6 +196,14 @@ private String extractClassPathResourceToTempLocation(final String hostPath) { return tmpLocation.getAbsolutePath(); } + private File createTempDirectory() { + try { + return Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), TESTCONTAINERS_TMP_DIR_PREFIX).toFile(); + } catch (IOException e) { + return new File(TESTCONTAINERS_TMP_DIR_PREFIX + Base58.randomString(5)); + } + } + @SuppressWarnings("ResultOfMethodCallIgnored") private void copyFromJarToLocation(final JarFile jarFile, final JarEntry entry, @@ -305,4 +315,4 @@ private int getUnixFileMode(final String pathAsString) { return mode; } } -} \ No newline at end of file +} From b7d72c6df24cfb9e57a8fc3b5c9ed6ee6b754ef8 Mon Sep 17 00:00:00 2001 From: Ihor Banadiga Date: Fri, 1 Sep 2017 15:44:25 +0300 Subject: [PATCH 2/4] CHANGELOG updated --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 087c2d3d68b..4130fca304f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. - Fixed TAR composition on Windows (#444) - Allowing `addExposedPort` to be used after ports have been specified with `withExposedPorts` (#453) - Stopping creation of temporary directory prior to creating temporary file (#443) +- Fixed temp files should be created in a temp directory (#423) ### Changed - Added `forResponsePredicate` method to HttpWaitStrategy to test response body (#441) From a0ff477ad3429ae0c22e172318fe3b369909aa4a Mon Sep 17 00:00:00 2001 From: Ihor Banadiga Date: Wed, 20 Sep 2017 20:16:24 +0300 Subject: [PATCH 3/4] Create tmp dir on MacOs. --- .../main/java/org/testcontainers/utility/MountableFile.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/testcontainers/utility/MountableFile.java b/core/src/main/java/org/testcontainers/utility/MountableFile.java index 2c6596f10c9..216436e882c 100644 --- a/core/src/main/java/org/testcontainers/utility/MountableFile.java +++ b/core/src/main/java/org/testcontainers/utility/MountableFile.java @@ -34,6 +34,7 @@ public class MountableFile implements Transferable { private static final String TESTCONTAINERS_TMP_DIR_PREFIX = ".testcontainers-tmp-"; + public static final String OS_MAC_TMP_DIR = "/tmp"; private final String path; @@ -198,7 +199,10 @@ private String extractClassPathResourceToTempLocation(final String hostPath) { private File createTempDirectory() { try { - return Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), TESTCONTAINERS_TMP_DIR_PREFIX).toFile(); + if (SystemUtils.IS_OS_MAC) { + return Files.createTempDirectory(Paths.get(OS_MAC_TMP_DIR), TESTCONTAINERS_TMP_DIR_PREFIX).toFile(); + } + return Files.createTempDirectory(TESTCONTAINERS_TMP_DIR_PREFIX).toFile(); } catch (IOException e) { return new File(TESTCONTAINERS_TMP_DIR_PREFIX + Base58.randomString(5)); } From be6dfad5c9a4733126fd5accf14f2d774847a729 Mon Sep 17 00:00:00 2001 From: Ihor Banadiga Date: Thu, 21 Sep 2017 22:10:45 +0300 Subject: [PATCH 4/4] Update MountableFile.java --- .../src/main/java/org/testcontainers/utility/MountableFile.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/testcontainers/utility/MountableFile.java b/core/src/main/java/org/testcontainers/utility/MountableFile.java index 216436e882c..71764194c1e 100644 --- a/core/src/main/java/org/testcontainers/utility/MountableFile.java +++ b/core/src/main/java/org/testcontainers/utility/MountableFile.java @@ -34,7 +34,7 @@ public class MountableFile implements Transferable { private static final String TESTCONTAINERS_TMP_DIR_PREFIX = ".testcontainers-tmp-"; - public static final String OS_MAC_TMP_DIR = "/tmp"; + private static final String OS_MAC_TMP_DIR = "/tmp"; private final String path;