Merge pull request from GHSA-g3wg-6mcf-8jj6
* Issue #5451 - Improving temp directory creation. + Using new Files.createTempDirectory() instead of nonsense around File.createTempFile() Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com> * Fixes #5451 - Restoring File.deleteOnExit
This commit is contained in:
parent
c73ad40511
commit
53e0e0e9b2
|
@ -24,6 +24,8 @@ import java.net.URI;
|
|||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -375,14 +377,10 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
@Override
|
||||
public void cloneConfigure(WebAppContext template, WebAppContext context) throws Exception
|
||||
{
|
||||
File tmpDir = File.createTempFile(WebInfConfiguration.getCanonicalNameForWebAppTmpDir(context), "", template.getTempDirectory().getParentFile());
|
||||
if (tmpDir.exists())
|
||||
{
|
||||
IO.delete(tmpDir);
|
||||
}
|
||||
tmpDir.mkdir();
|
||||
tmpDir.deleteOnExit();
|
||||
context.setTempDirectory(tmpDir);
|
||||
Path tmpDir = Files.createTempDirectory(template.getTempDirectory().getParentFile().toPath(), WebInfConfiguration.getCanonicalNameForWebAppTmpDir(context));
|
||||
File tmpDirAsFile = tmpDir.toFile();
|
||||
tmpDirAsFile.deleteOnExit();
|
||||
context.setTempDirectory(tmpDirAsFile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -510,11 +508,7 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
else
|
||||
{
|
||||
//ensure file will always be unique by appending random digits
|
||||
tmpDir = File.createTempFile(temp, ".dir", parent);
|
||||
//delete the file that was created
|
||||
tmpDir.delete();
|
||||
//and make a directory of the same name
|
||||
tmpDir.mkdirs();
|
||||
tmpDir = Files.createTempDirectory(parent.toPath(), temp).toFile();
|
||||
}
|
||||
configureTempDirectory(tmpDir, context);
|
||||
|
||||
|
|
Loading…
Reference in New Issue