fix(cbx): drain NightCompress InputStream before closing (#1004)
This commit is contained in:
@@ -14,6 +14,7 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
@@ -97,7 +98,13 @@ public class ArchiveService {
|
|||||||
lock.lock();
|
lock.lock();
|
||||||
try (InputStream inputStream = Archive.getInputStream(path, entryName)) {
|
try (InputStream inputStream = Archive.getInputStream(path, entryName)) {
|
||||||
if (inputStream != null) {
|
if (inputStream != null) {
|
||||||
|
try {
|
||||||
return inputStream.transferTo(outputStream);
|
return inputStream.transferTo(outputStream);
|
||||||
|
} finally {
|
||||||
|
// NightCompress fails with a SIGSEGV if you do not read the
|
||||||
|
// entirety of the input stream from the zip.
|
||||||
|
inputStream.transferTo(OutputStream.nullOutputStream());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IOException("Failed to extract from archive: " + e.getMessage(), e);
|
throw new IOException("Failed to extract from archive: " + e.getMessage(), e);
|
||||||
@@ -185,16 +192,24 @@ public class ArchiveService {
|
|||||||
requireAvailable();
|
requireAvailable();
|
||||||
ReentrantLock lock = getFileLock(path);
|
ReentrantLock lock = getFileLock(path);
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try (InputStream inputStream = Archive.getInputStream(path, entryName)) {
|
|
||||||
if (inputStream != null) {
|
boolean hasCreatedFile = false;
|
||||||
return Files.copy(inputStream, outputPath);
|
try (OutputStream outputStream = Files.newOutputStream(outputPath, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)) {
|
||||||
}
|
hasCreatedFile = true;
|
||||||
|
|
||||||
|
return transferEntryTo(path, entryName, outputStream);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (hasCreatedFile) {
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(outputPath);
|
||||||
|
} catch (Exception ce) {
|
||||||
|
e.addSuppressed(ce);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
throw new IOException("Failed to extract from archive: " + e.getMessage(), e);
|
throw new IOException("Failed to extract from archive: " + e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IOException("Entry not found in archive");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user