diff --git a/capsule/src/main/java/Capsule.java b/capsule/src/main/java/Capsule.java index 57ef661..3b28059 100644 --- a/capsule/src/main/java/Capsule.java +++ b/capsule/src/main/java/Capsule.java @@ -52,6 +52,7 @@ import java.nio.channels.FileLock; import java.nio.charset.Charset; import java.nio.file.DirectoryStream; +import java.nio.file.FileAlreadyExistsException; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Files; @@ -81,6 +82,7 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.Properties; +import java.util.Random; import java.util.RandomAccess; import java.util.Set; import java.util.StringTokenizer; @@ -5459,7 +5461,8 @@ static Path createPathingJar(Path dir, List cp) { try { final Path absolutePath = dir.toAbsolutePath(); final List paths = createPathingClassPath(absolutePath, cp); - final Path pathingJar = Files.createTempFile(absolutePath, "capsule_pathing_jar", ".jar"); + + final Path pathingJar = createTempFile(absolutePath, "capsule_pathing_jar", ".jar"); final Manifest man = new Manifest(); man.getMainAttributes().putValue(ATTR_MANIFEST_VERSION, "1.0"); man.getMainAttributes().putValue(ATTR_CLASS_PATH, join(paths, " ")); @@ -5471,6 +5474,22 @@ static Path createPathingJar(Path dir, List cp) { } } + private static Path createTempFile(Path dir, String prefix, String suffix) throws IOException + { + for (;;) + { + try + { + String rand = Long.toUnsignedString(new Random().nextLong(), 16); + return Files.createFile(dir.resolve(prefix + rand + suffix)); + } + catch (FileAlreadyExistsException ex) + { + // ignore + } + } + } + private static List createPathingClassPath(Path dir, List cp) { boolean allPathsHaveSameRoot = true; for (Path p : cp) {