From 53aece5e85d0b216c66a592e1b5d41e9134c17df Mon Sep 17 00:00:00 2001 From: damage Date: Mon, 23 Dec 2024 11:10:04 +0100 Subject: [PATCH] delete zip after download --- .../de/devloop/mavor/servlet/DownloadZip.java | 22 ++++++++++++------- src/main/webapp/download.jsp | 8 +++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/devloop/mavor/servlet/DownloadZip.java b/src/main/java/de/devloop/mavor/servlet/DownloadZip.java index 266246f..caa2c18 100644 --- a/src/main/java/de/devloop/mavor/servlet/DownloadZip.java +++ b/src/main/java/de/devloop/mavor/servlet/DownloadZip.java @@ -23,15 +23,21 @@ public class DownloadZip extends AuthenticatedServlet { protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String zipFilename = req.getParameter(PARAMETER_FILENAME); File zipFile = new File(tempDir, zipFilename); - if (zipFile.getParentFile().getCanonicalPath().equals(tempDir.getCanonicalPath())) { - resp.addHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", zipFilename)); - resp.setContentType("application/zip"); - resp.setContentLengthLong(zipFile.length()); - FileInputStream fileInputStream = new FileInputStream(zipFile); - fileInputStream.transferTo(resp.getOutputStream()); - fileInputStream.close(); + + if (zipFile.exists()) { + if (zipFile.getParentFile().getCanonicalPath().equals(tempDir.getCanonicalPath())) { + resp.addHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", zipFilename)); + resp.setContentType("application/zip"); + resp.setContentLengthLong(zipFile.length()); + FileInputStream fileInputStream = new FileInputStream(zipFile); + fileInputStream.transferTo(resp.getOutputStream()); + fileInputStream.close(); + zipFile.delete(); + } else { + throw new ServletException("-.-"); + } } else { - throw new ServletException("-.-"); + resp.sendRedirect("/mavor"); } } } diff --git a/src/main/webapp/download.jsp b/src/main/webapp/download.jsp index 4a15f09..7de790a 100644 --- a/src/main/webapp/download.jsp +++ b/src/main/webapp/download.jsp @@ -2,9 +2,9 @@ <%@ page isELIgnored="false" %> - Output:
-
${stdout}

- File: ${zipFilename}
- logout | back + Download dependencies (Link only works once!): ${zipFilename}
+ logout | back
+ Maven Output:
+
${stdout}