From 4bce9a234214a0b0893aaeb67e1cc32ba3321635 Mon Sep 17 00:00:00 2001 From: hsuk04 <126087202+hsuk04@users.noreply.github.com> Date: Wed, 28 May 2025 00:54:04 +0800 Subject: [PATCH] Refactor createTempDirectory method to use java.nio.file.Files for secure and atomic temporary directory creation (#1559) Signed-off-by: hsuk04 --- .../commons/frameworks/core/util/FileUtil.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/eclipse-language-servers/org.springsource.ide.eclipse.commons.frameworks.core/src/org/springsource/ide/eclipse/commons/frameworks/core/util/FileUtil.java b/eclipse-language-servers/org.springsource.ide.eclipse.commons.frameworks.core/src/org/springsource/ide/eclipse/commons/frameworks/core/util/FileUtil.java index 92de67c7e..14b1074f0 100644 --- a/eclipse-language-servers/org.springsource.ide.eclipse.commons.frameworks.core/src/org/springsource/ide/eclipse/commons/frameworks/core/util/FileUtil.java +++ b/eclipse-language-servers/org.springsource.ide.eclipse.commons.frameworks.core/src/org/springsource/ide/eclipse/commons/frameworks/core/util/FileUtil.java @@ -12,7 +12,8 @@ package org.springsource.ide.eclipse.commons.frameworks.core.util; import java.io.File; import java.io.IOException; - +import java.nio.file.Files; +import java.nio.file.Path; /** * @author Steffen Pingel * @author Leo Dos Santos @@ -56,13 +57,8 @@ public class FileUtil { * @throws IOException */ public static File createTempDirectory(String name, String suffix) throws IOException { - File tempFolder = File.createTempFile(name, suffix); - if (!tempFolder.delete()) { - throw new IOException("Could not delete temp file: " + tempFolder.getAbsolutePath()); - } - if (!tempFolder.mkdirs()) { - throw new IOException("Could not create temp directory: " + tempFolder.getAbsolutePath()); - } + String tempDirPrefix = (name != null ? name : "") + (suffix != null ? suffix : ""); + File tempFolder = Files.createTempDirectory(tempDirPrefix).toFile(); deleteOnShutdown(tempFolder); return tempFolder; }