Improved temporary file removing.

This commit is contained in:
Christian P. MOMON 2022-02-20 02:16:47 +01:00
parent d017781858
commit 380028376a

View file

@ -105,9 +105,9 @@ public class Crawler
{
logger.info("Crawling {}", url);
File downloadFile = null;
try
{
File downloadFile;
try
{
downloadFile = download(url);
@ -158,6 +158,7 @@ public class Crawler
{
logger.error("ERROR: bad child class [{}][{}].", downloadClass, parent);
this.journal.add(url, parentURL, CrawlStatus.BADCHILDCLASS);
downloadFile.delete();
}
else
{
@ -177,6 +178,7 @@ public class Crawler
if (StringUtils.equals(downloadSha, storedSha))
{
this.journal.add(url, parentURL, CrawlStatus.SUCCESS);
downloadFile.delete();
}
else
{
@ -234,6 +236,13 @@ public class Crawler
{
this.journal.add(url, parentURL, CrawlStatus.IOERROR);
}
finally
{
if ((downloadFile != null) && (downloadFile.exists()))
{
downloadFile.delete();
}
}
}
/**
@ -325,6 +334,7 @@ public class Crawler
{
final int TIMEOUT = 5000;
result = Files.createTempFile("tmp-", ".statoolsinfos").toFile();
result.deleteOnExit();
FileUtils.copyURLToFile(url, result, TIMEOUT, TIMEOUT);
}