Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/61#discussion_r14806538
--- Diff: utils/common/src/main/java/brooklyn/util/os/Os.java ---
@@ -544,13 +545,23 @@ public static File newTempFile(Class<?> clazz, String
ext) {
/** creates a temp dir which will be deleted on exit */
public static File newTempDir(String prefix) {
- String baseName = (prefix==null ? "" : prefix + "-") +
Identifiers.makeRandomId(4);
- File tempDir = new File(tmp(), baseName);
- if (tempDir.mkdir()) {
- Os.deleteOnExitRecursively(tempDir);
- return tempDir;
+ String sanitizedPrefix = (prefix==null ? "" : prefix + "-");
+ String tmpParent = tmp();
+ for (int i = 0; i < TEMP_DIR_ATTEMPTS; i++) {
+ String baseName = sanitizedPrefix +
Identifiers.makeRandomId(4);
+ File tempDir = new File(tmpParent, baseName);
+ if (!tempDir.exists()) {
+ if (tempDir.mkdir()) {
+ Os.deleteOnExitRecursively(tempDir);
+ return tempDir;
+ } else {
+ log.warn("Attempt to create temp dir failed " +
tempDir);
+ }
+ } else {
+ log.debug("Attemp to create temp dir failed, already
exists " + tempDir);
--- End diff --
missing a `t` in `Attempt`
worth a comment that this collision is unlikely due to the `makeRandomId`
but with lots of temp dirs it can start to happen ?
if the creation failed (`log.warn`), e.g. because a directory was not
writable or disk is full, do we really want to retry 1000 times? maybe set
`ATTEMPTS` much lower?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---