Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/61#discussion_r14808596
  
    --- 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 --
    
    > do we really want to retry 1000 times?
    The implementations for createTempFile and createTempDirectory(Java 7+) 
loop indefinitely until a unique name is found. The guava implementation 
(com.google.common.io.Files.createTempDir()) retries 10 000 times.
    Considering this it might be a good idea even to increase it :)


---
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.
---

Reply via email to