Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent attempt to create Vert.x caching dir caching is disabled #28142

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,15 @@ private static VertxOptions convertToVertxOptions(VertxConfiguration conf, Vertx
initializeClusterOptions(conf, options);
}

FileSystemOptions fileSystemOptions = new FileSystemOptions()
.setFileCachingEnabled(conf.caching)
.setClassPathResolvingEnabled(conf.classpathResolving);

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()) {
boolean cacheDirRequired = conf.caching || conf.classpathResolving;
if (!tmp.isDirectory() && cacheDirRequired) {
if (!tmp.mkdirs()) {
LOGGER.warnf("Unable to create Vert.x cache directory : %s", tmp.getAbsolutePath());
}
Expand All @@ -322,26 +327,25 @@ private static VertxOptions convertToVertxOptions(VertxConfiguration conf, Vertx
}
}

File cache = getRandomDirectory(tmp);
LOGGER.debugf("Vert.x Cache configured to: %s", cache.getAbsolutePath());
fileCacheDir = cache.getAbsolutePath();
if (shutdown != null) {
shutdown.addLastShutdownTask(new Runnable() {
@Override
public void run() {
// Recursively delete the created directory and all the files
deleteDirectory(cache);
// We do not delete the vertx-cache directory on purpose, as it could be used concurrently by
// another application. In the worse case, it's just an empty directory.
}
});
if (cacheDirRequired) {
File cache = getRandomDirectory(tmp);
LOGGER.debugf("Vert.x Cache configured to: %s", cache.getAbsolutePath());
fileSystemOptions.setFileCacheDir(cache.getAbsolutePath());
if (shutdown != null) {
shutdown.addLastShutdownTask(new Runnable() {
@Override
public void run() {
// Recursively delete the created directory and all the files
deleteDirectory(cache);
// We do not delete the vertx-cache directory on purpose, as it could be used concurrently by
// another application. In the worse case, it's just an empty directory.
}
});
}
}
}

options.setFileSystemOptions(new FileSystemOptions()
.setFileCachingEnabled(conf.caching)
.setFileCacheDir(fileCacheDir)
.setClassPathResolvingEnabled(conf.classpathResolving));
options.setFileSystemOptions(fileSystemOptions);
options.setWorkerPoolSize(conf.workerPoolSize);
options.setInternalBlockingPoolSize(conf.internalBlockingPoolSize);
blockingThreadPoolSize = conf.internalBlockingPoolSize;
Expand Down