Skip to content

Commit 4bce9a2

Browse files
authored
Refactor createTempDirectory method to use java.nio.file.Files for secure and atomic temporary directory creation (#1559)
Signed-off-by: hsuk04 <hsuhweek@gmail.com>
1 parent 0cbb4ba commit 4bce9a2

File tree

1 file changed

+4
-8
lines changed
  • eclipse-language-servers/org.springsource.ide.eclipse.commons.frameworks.core/src/org/springsource/ide/eclipse/commons/frameworks/core/util

1 file changed

+4
-8
lines changed

eclipse-language-servers/org.springsource.ide.eclipse.commons.frameworks.core/src/org/springsource/ide/eclipse/commons/frameworks/core/util/FileUtil.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
import java.io.File;
1414
import java.io.IOException;
15-
15+
import java.nio.file.Files;
16+
import java.nio.file.Path;
1617
/**
1718
* @author Steffen Pingel
1819
* @author Leo Dos Santos
@@ -56,13 +57,8 @@ public static File createTempDirectory(String name) throws IOException {
5657
* @throws IOException
5758
*/
5859
public static File createTempDirectory(String name, String suffix) throws IOException {
59-
File tempFolder = File.createTempFile(name, suffix);
60-
if (!tempFolder.delete()) {
61-
throw new IOException("Could not delete temp file: " + tempFolder.getAbsolutePath());
62-
}
63-
if (!tempFolder.mkdirs()) {
64-
throw new IOException("Could not create temp directory: " + tempFolder.getAbsolutePath());
65-
}
60+
String tempDirPrefix = (name != null ? name : "") + (suffix != null ? suffix : "");
61+
File tempFolder = Files.createTempDirectory(tempDirPrefix).toFile();
6662
deleteOnShutdown(tempFolder);
6763
return tempFolder;
6864
}

0 commit comments

Comments
 (0)