diff --git a/src/main/java/org/qortal/api/resource/ArbitraryResource.java b/src/main/java/org/qortal/api/resource/ArbitraryResource.java index 1e934b09..46bd9c5b 100644 --- a/src/main/java/org/qortal/api/resource/ArbitraryResource.java +++ b/src/main/java/org/qortal/api/resource/ArbitraryResource.java @@ -275,7 +275,7 @@ public class ArbitraryResource { ArbitraryDataWriter arbitraryDataWriter = new ArbitraryDataWriter(Paths.get(path), name, service, method, compression); try { arbitraryDataWriter.save(); - } catch (IOException | DataException e) { + } catch (IOException | DataException | InterruptedException e) { LOGGER.info("Unable to create arbitrary data file: {}", e.getMessage()); throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE); } catch (RuntimeException e) { diff --git a/src/main/java/org/qortal/api/resource/WebsiteResource.java b/src/main/java/org/qortal/api/resource/WebsiteResource.java index 43ba30c7..588a8cd2 100644 --- a/src/main/java/org/qortal/api/resource/WebsiteResource.java +++ b/src/main/java/org/qortal/api/resource/WebsiteResource.java @@ -109,7 +109,7 @@ public class WebsiteResource { ArbitraryDataWriter arbitraryDataWriter = new ArbitraryDataWriter(Paths.get(path), name, service, method, compression); try { arbitraryDataWriter.save(); - } catch (IOException | DataException e) { + } catch (IOException | DataException | InterruptedException e) { LOGGER.info("Unable to create arbitrary data file: {}", e.getMessage()); throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE); } catch (RuntimeException e) { @@ -211,7 +211,7 @@ public class WebsiteResource { ArbitraryDataWriter arbitraryDataWriter = new ArbitraryDataWriter(Paths.get(directoryPath), name, service, method, compression); try { arbitraryDataWriter.save(); - } catch (IOException | DataException e) { + } catch (IOException | DataException | InterruptedException e) { LOGGER.info("Unable to create arbitrary data file: {}", e.getMessage()); throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE); } catch (RuntimeException e) { diff --git a/src/main/java/org/qortal/arbitrary/ArbitraryDataWriter.java b/src/main/java/org/qortal/arbitrary/ArbitraryDataWriter.java index d9f284e7..5165cbf2 100644 --- a/src/main/java/org/qortal/arbitrary/ArbitraryDataWriter.java +++ b/src/main/java/org/qortal/arbitrary/ArbitraryDataWriter.java @@ -52,7 +52,7 @@ public class ArbitraryDataWriter { this.compression = compression; } - public void save() throws IllegalStateException, IOException, DataException { + public void save() throws IllegalStateException, IOException, DataException, InterruptedException { try { this.preExecute(); this.process(); @@ -136,7 +136,7 @@ public class ArbitraryDataWriter { this.validatePatch(); } - private void validatePatch() throws IOException { + private void validatePatch() { if (this.filePath == null) { throw new IllegalStateException("Null path after creating patch"); } @@ -158,13 +158,14 @@ public class ArbitraryDataWriter { } } - private void compress() { + private void compress() throws InterruptedException { // Compress the data if requested if (this.compression != Compression.NONE) { this.compressedPath = Paths.get(this.workingPath.toString() + File.separator + "data.zip"); try { if (this.compression == Compression.ZIP) { + LOGGER.info("Compressing..."); ZipUtils.zip(this.filePath.toString(), this.compressedPath.toString(), "data"); } else { @@ -190,6 +191,7 @@ public class ArbitraryDataWriter { this.encryptedPath = Paths.get(this.workingPath.toString() + File.separator + "data.zip.encrypted"); try { // Encrypt the file with AES + LOGGER.info("Encrypting..."); this.aesKey = AES.generateKey(256); AES.encryptFile("AES", this.aesKey, this.filePath.toString(), this.encryptedPath.toString()); diff --git a/src/main/java/org/qortal/utils/ZipUtils.java b/src/main/java/org/qortal/utils/ZipUtils.java index 2ccffc63..6e614aef 100644 --- a/src/main/java/org/qortal/utils/ZipUtils.java +++ b/src/main/java/org/qortal/utils/ZipUtils.java @@ -25,6 +25,8 @@ package org.qortal.utils; +import org.qortal.controller.Controller; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -35,7 +37,7 @@ import java.util.zip.ZipOutputStream; public class ZipUtils { - public static void zip(String sourcePath, String destFilePath, String fileName) throws IOException { + public static void zip(String sourcePath, String destFilePath, String fileName) throws IOException, InterruptedException { File sourceFile = new File(sourcePath); if (fileName == null) { fileName = sourceFile.getName(); @@ -47,7 +49,10 @@ public class ZipUtils { fileOutputStream.close(); } - public static void zip(final File fileToZip, final String fileName, final ZipOutputStream zipOut) throws IOException { + public static void zip(final File fileToZip, final String fileName, final ZipOutputStream zipOut) throws IOException, InterruptedException { + if (Controller.isStopping()) { + throw new InterruptedException("Controller is stopping"); + } if (fileToZip.isDirectory()) { if (fileName.endsWith("/")) { zipOut.putNextEntry(new ZipEntry(fileName));