11package 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 ;
137import java .io .File ;
148import java .io .IOException ;
159import java .io .InputStream ;
2519import java .util .Set ;
2620import java .util .jar .JarEntry ;
2721import 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
3736@ Slf4j
3837public 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