mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-15 08:13:43 +01:00
created a new getTempFile() to FileUtils that does not create the file, it only generates the file name
Former-commit-id: 04e275caade0deba97b3b03cf41fa48f962c0172
This commit is contained in:
@@ -112,10 +112,7 @@ public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer {
|
||||
final Pattern uriRx = Pattern.compile("^(https?|file)\\:.*", Pattern.CASE_INSENSITIVE);
|
||||
if (uriRx.matcher(suppressionFilePath).matches()) {
|
||||
deleteTempFile = true;
|
||||
file = File.createTempFile("suppression", ".xml", Settings.getTempDirectory());
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
file = FileUtils.getTempFile("suppression", "xml");
|
||||
final URL url = new URL(suppressionFilePath);
|
||||
try {
|
||||
Downloader.fetchFile(url, file, false);
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.ZipEntry;
|
||||
@@ -86,6 +87,26 @@ public final class FileUtils {
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new temporary file name that is guaranteed to be unique.
|
||||
*
|
||||
* @param prefix the prefix for the file name to generate
|
||||
* @param extension the extension of the generated file name
|
||||
* @return a temporary File
|
||||
*/
|
||||
public static File getTempFile(String prefix, String extension) {
|
||||
final File dir = Settings.getTempDirectory();
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
final String tempFileName = String.format("%s%s.%s", prefix, UUID.randomUUID().toString(), extension);
|
||||
final File tempFile = new File(dir, tempFileName);
|
||||
if (tempFile.exists()) {
|
||||
return getTempFile(prefix, extension);
|
||||
}
|
||||
return tempFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data directory. If a path was specified in dependencycheck.properties or was specified using the
|
||||
* Settings object, and the path exists, that path will be returned as a File object. If it does not exist, then a
|
||||
|
||||
Reference in New Issue
Block a user