diff --git a/src/fr/devinsy/statoolinfos/crawl/Crawler.java b/src/fr/devinsy/statoolinfos/crawl/Crawler.java index dcd240f..9b2d5c5 100644 --- a/src/fr/devinsy/statoolinfos/crawl/Crawler.java +++ b/src/fr/devinsy/statoolinfos/crawl/Crawler.java @@ -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); }