From 2652931b48fa7f4fdcd4a60d11abdd38f7edc8dc Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 22 Sep 2022 09:31:41 +0300 Subject: [PATCH] Prevent attempt to create Vert.x caching dir caching is disabled Closes: #28094 --- .../vertx/core/runtime/VertxCoreRecorder.java | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java b/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java index 1d4ff48c2413d..05d88e50dbd35 100644 --- a/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java +++ b/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java @@ -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()); } @@ -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;