Skip to content

Commit

Permalink
Improve random directory generation:
Browse files Browse the repository at this point in the history
* make sure it does not exist
* avoid negative numbers
  • Loading branch information
cescoffier committed Mar 9, 2021
1 parent 394286e commit f4a6aaf
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ private static VertxOptions convertToVertxOptions(VertxConfiguration conf, Vertx
}
}

long random = UUID.randomUUID().getMostSignificantBits();
File cache = new File(tmp, Long.toString(random));
File cache = getRandomDirectory(tmp);
LOGGER.debugf("Vert.x Cache configured to: %s", cache.getAbsolutePath());
fileCacheDir = cache.getAbsolutePath();
if (shutdown != null) {
Expand Down Expand Up @@ -291,6 +290,16 @@ public void run() {
return options;
}

private static File getRandomDirectory(File tmp) {
long random = Math.abs(UUID.randomUUID().getMostSignificantBits());
File cache = new File(tmp, Long.toString(random));
if (cache.isDirectory()) {
// Do not reuse an existing directory.
return getRandomDirectory(tmp);
}
return cache;
}

private static int calculateDefaultIOThreads() {
//we only allow one event loop per 10mb of ram at the most
//its hard to say what this number should be, but it is also obvious
Expand Down

0 comments on commit f4a6aaf

Please sign in to comment.