From 953de352675a4ad91fe307d816a4ea7780c94274 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 26 Aug 2012 13:39:58 +0200 Subject: [PATCH] Fix calculation of project size. --- .../jsite/application/ProjectInserter.java | 29 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/de/todesbaum/jsite/application/ProjectInserter.java b/src/de/todesbaum/jsite/application/ProjectInserter.java index eb5abda..b5f2e16 100644 --- a/src/de/todesbaum/jsite/application/ProjectInserter.java +++ b/src/de/todesbaum/jsite/application/ProjectInserter.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.concurrent.CountDownLatch; import java.util.logging.Level; import java.util.logging.Logger; @@ -392,7 +393,6 @@ public class ProjectInserter implements FileScannerListener, Runnable { checkReport.addIssue("error.no-files-to-insert", true); } Set fileNames = new HashSet(); - long totalSize = 0; for (Entry fileOptionEntry : fileOptionEntries) { FileOption fileOption = fileOptionEntry.getValue(); if (!fileOption.isInsert() && !fileOption.isInsertRedirect()) { @@ -407,9 +407,32 @@ public class ProjectInserter implements FileScannerListener, Runnable { if (!fileNames.add(fileName)) { checkReport.addIssue("error.duplicate-file", true, fileName); } - if (fileOption.isInsert()) { - totalSize += new File(project.getLocalPath(), fileName).length(); + } + long totalSize = 0; + FileScanner fileScanner = new FileScanner(project); + final CountDownLatch completionLatch = new CountDownLatch(1); + fileScanner.addFileScannerListener(new FileScannerListener() { + + @Override + public void fileScannerFinished(FileScanner fileScanner) { + completionLatch.countDown(); + } + }); + new Thread(fileScanner).start(); + while (completionLatch.getCount() > 0) { + try { + completionLatch.await(); + } catch (InterruptedException ie1) { + /* TODO: logging */ + } + } + for (ScannedFile scannedFile : fileScanner.getFiles()) { + String fileName = scannedFile.getFilename(); + FileOption fileOption = project.getFileOption(fileName); + if ((fileOption != null) && !fileOption.isInsert()) { + continue; } + totalSize += new File(project.getLocalPath(), fileName).length(); } if (totalSize > 2 * 1024 * 1024) { checkReport.addIssue("warning.site-larger-than-2-mib", false); -- 2.7.4