Fix calculation of project size.
[jSite.git] / src / de / todesbaum / jsite / application / ProjectInserter.java
index 1f5e8ef..b5f2e16 100644 (file)
@@ -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;
 
@@ -326,7 +327,7 @@ public class ProjectInserter implements FileScannerListener, Runnable {
                        if (!fileOption.isForceInsert() && file.getHash().equals(fileOption.getLastInsertHash())) {
                                /* only insert a redirect. */
                                logger.log(Level.FINE, String.format("Inserting redirect to edition %d for %s.", fileOption.getLastInsertEdition(), filename));
-                               return new RedirectFileEntry(filename, fileOption.getMimeType(), "SSK@" + project.getRequestURI() + "/" + project.getPath() + "-" + fileOption.getLastInsertEdition() + "/" + filename);
+                               return new RedirectFileEntry(fileOption.hasChangedName() ? fileOption.getChangedName() : filename, fileOption.getMimeType(), "SSK@" + project.getRequestURI() + "/" + project.getPath() + "-" + fileOption.getLastInsertEdition() + "/" + fileOption.getLastInsertFilename());
                        }
                        try {
                                long[] fileLength = new long[1];
@@ -407,6 +408,35 @@ public class ProjectInserter implements FileScannerListener, Runnable {
                                checkReport.addIssue("error.duplicate-file", true, fileName);
                        }
                }
+               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);
+               }
                return checkReport;
        }