Skip to content

Commit

Permalink
Simplify temp directory creation and improve diagnostics
Browse files Browse the repository at this point in the history
Closes gh-23622
  • Loading branch information
wilkinsona committed Oct 13, 2020
1 parent ce70e7d commit 667ccda
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;

import org.springframework.core.io.FileSystemResourceLoader;
import org.springframework.core.io.Resource;
Expand Down Expand Up @@ -93,9 +94,7 @@ public URL getResource(String path) throws MalformedURLException {
try {
if (this.emptyRootFolder == null) {
synchronized (this) {
File tempFolder = File.createTempFile("spr", "servlet");
tempFolder.delete();
tempFolder.mkdirs();
File tempFolder = Files.createTempDirectory("spr-servlet").toFile();
tempFolder.deleteOnExit();
this.emptyRootFolder = tempFolder;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
Expand Down Expand Up @@ -169,9 +170,7 @@ public void setServerHeader(String serverHeader) {
*/
protected final File createTempDir(String prefix) {
try {
File tempDir = File.createTempFile(prefix + ".", "." + getPort());
tempDir.delete();
tempDir.mkdir();
File tempDir = Files.createTempDirectory(prefix + "." + getPort() + ".").toFile();

This comment has been minimized.

Copy link
@dreis2211

dreis2211 Oct 13, 2020

Contributor

Is the trailing dot really needed? Seems weird

This comment has been minimized.

Copy link
@wilkinsona

wilkinsona Oct 13, 2020

Author Member

It's not a necessity. I kept it to align as best we can with the old prefix where it ended with a ..

tempDir.deleteOnExit();
return tempDir;
}
Expand Down

0 comments on commit 667ccda

Please sign in to comment.