Skip to content

Commit

Permalink
Create /tmp/vertx-cache and configure it to be world-readable and wri…
Browse files Browse the repository at this point in the history
…table.

Under that directory, another random directory is created that is only readable and writable from the current user.

The vertx-cache directory creation is disabled if:

* the user specifies a cache directory
* the vertx-cache directory already exists

Fix #7678
  • Loading branch information
cescoffier committed Mar 8, 2021
1 parent 0ec090d commit 181597b
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -51,6 +52,7 @@
public class VertxCoreRecorder {

private static final Logger LOGGER = Logger.getLogger(VertxCoreRecorder.class.getName());
public static final String VERTX_CACHE = "vertx-cache";

static volatile VertxSupplier vertx;

Expand Down Expand Up @@ -227,8 +229,24 @@ private static VertxOptions convertToVertxOptions(VertxConfiguration conf, Vertx
initializeClusterOptions(conf, options);
}

String fileCacheDir = System.getProperty(CACHE_DIR_BASE_PROP_NAME,
System.getProperty("java.io.tmpdir", ".") + File.separator + "vertx-cache");
String fileCacheDir = System.getProperty(CACHE_DIR_BASE_PROP_NAME);
if (fileCacheDir == null) {
File tmp = new File(System.getProperty("java.io.tmpdir", ".") + File.separator + VERTX_CACHE);
if (!tmp.isDirectory()) {
if (!tmp.mkdirs()) {
LOGGER.warnf("Unable to create Vert.x cache directory : %s", tmp.getAbsolutePath());
}
if (!(tmp.setReadable(true, false) && tmp.setWritable(true, false))) {
LOGGER.warnf("Unable to make the Vert.x cache directory (%s) world readable and writable",
tmp.getAbsolutePath());
}
}

long random = UUID.randomUUID().getMostSignificantBits();
File cache = new File(tmp, Long.toString(random));
LOGGER.debugf("Vert.x Cache configured to: %s", cache.getAbsolutePath());
fileCacheDir = cache.getAbsolutePath();
}

options.setFileSystemOptions(new FileSystemOptions()
.setFileCachingEnabled(conf.caching)
Expand Down

0 comments on commit 181597b

Please sign in to comment.