forked from Qortal/qortal
Handle shutdowns when zipping a large number of files.
This commit is contained in:
parent
77479215a6
commit
59ef66f46d
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user