X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fde%2Ftodesbaum%2Fjsite%2Fapplication%2FProjectInserter.java;h=a3fb0da755badf79b474008b5570e056bfe18979;hb=8bc7a8f2372639a9fbeea34f9cbee9697f34ba3f;hp=d16be3edd955f72c90c0c7aae8b538e48df3a718;hpb=66b60fe3515217a8c2892a20ee79524ce3a919e2;p=jSite.git diff --git a/src/de/todesbaum/jsite/application/ProjectInserter.java b/src/de/todesbaum/jsite/application/ProjectInserter.java index d16be3e..a3fb0da 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; @@ -326,18 +327,18 @@ 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]; InputStream fileEntryInputStream = createFileInputStream(filename, fileOption, edition, fileLength); - fileEntry = new DirectFileEntry(filename, fileOption.getMimeType(), fileEntryInputStream, fileLength[0]); + fileEntry = new DirectFileEntry(fileOption.hasChangedName() ? fileOption.getChangedName() : filename, fileOption.getMimeType(), fileEntryInputStream, fileLength[0]); } catch (IOException ioe1) { /* ignore, null is returned. */ } } else { if (fileOption.isInsertRedirect()) { - fileEntry = new RedirectFileEntry(filename, fileOption.getMimeType(), fileOption.getCustomKey()); + fileEntry = new RedirectFileEntry(fileOption.hasChangedName() ? fileOption.getChangedName() : filename, fileOption.getMimeType(), fileOption.getCustomKey()); } } return fileEntry; @@ -407,12 +408,42 @@ 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; } /** * {@inheritDoc} */ + @Override public void run() { fireProjectInsertStarted(); List files = fileScanner.getFiles(); @@ -518,6 +549,7 @@ public class ProjectInserter implements FileScannerListener, Runnable { /** * {@inheritDoc} */ + @Override public void fileScannerFinished(FileScanner fileScanner) { if (!fileScanner.isError()) { new Thread(this).start(); @@ -567,6 +599,7 @@ public class ProjectInserter implements FileScannerListener, Runnable { /** * {@inheritDoc} */ + @Override public Iterator iterator() { return issues.iterator(); }