-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create temp files in a temp directory #450
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,9 @@ | |
@Slf4j | ||
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; | ||
|
||
@Getter(lazy = true) | ||
|
@@ -163,7 +166,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 +197,17 @@ private String extractClassPathResourceToTempLocation(final String hostPath) { | |
return tmpLocation.getAbsolutePath(); | ||
} | ||
|
||
private File createTempDirectory() { | ||
try { | ||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please explain the conditions and circumstances, under which you expect this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example user runs java with params In cases, the folder does not exist we will get IOException. I think we could try to create a temp folder in the current folder as it was before. Is it make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, sounds good. |
||
return new File(TESTCONTAINERS_TMP_DIR_PREFIX + Base58.randomString(5)); | ||
} | ||
} | ||
|
||
@SuppressWarnings("ResultOfMethodCallIgnored") | ||
private void copyFromJarToLocation(final JarFile jarFile, | ||
final JarEntry entry, | ||
|
@@ -305,4 +319,4 @@ private int getUnixFileMode(final String pathAsString) { | |
return mode; | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be public?