diff --git a/bag_unpacker/src/main/scala/weco/storage_service/bag_unpacker/services/Unpacker.scala b/bag_unpacker/src/main/scala/weco/storage_service/bag_unpacker/services/Unpacker.scala index 3a877b400..2120e6412 100644 --- a/bag_unpacker/src/main/scala/weco/storage_service/bag_unpacker/services/Unpacker.scala +++ b/bag_unpacker/src/main/scala/weco/storage_service/bag_unpacker/services/Unpacker.scala @@ -190,7 +190,7 @@ trait Unpacker[ case err: IOException if err.getMessage == "Error detected parsing the header" => UnpackerUnarchiverError(UnexpectedUnarchiverError(err)) - case err: IOException if err.getMessage.startsWith("unexpected EOF") => + case err: IOException if err.getMessage.startsWith("unexpected EOF") || err.getMessage.startsWith("Truncated TAR archive") => UnpackerEOFError(err) case err => UnpackerUnexpectedError(err) } diff --git a/bag_unpacker/src/main/scala/weco/storage_service/bag_unpacker/storage/Unarchiver.scala b/bag_unpacker/src/main/scala/weco/storage_service/bag_unpacker/storage/Unarchiver.scala index 35ed859a2..423ab5a71 100644 --- a/bag_unpacker/src/main/scala/weco/storage_service/bag_unpacker/storage/Unarchiver.scala +++ b/bag_unpacker/src/main/scala/weco/storage_service/bag_unpacker/storage/Unarchiver.scala @@ -50,7 +50,7 @@ object Unarchiver { } yield iterator private def createIterator( - archiveInputStream: ArchiveInputStream + archiveInputStream: ArchiveInputStream[ArchiveEntry] ): Iterator[(ArchiveEntry, InputStream)] = new Iterator[(ArchiveEntry, InputStream)] { private var latest: ArchiveEntry = _ @@ -90,13 +90,13 @@ object Unarchiver { } private def extract( inputStream: InputStream - ): Either[UnarchiverError, ArchiveInputStream] = + ): Either[UnarchiverError, ArchiveInputStream[ArchiveEntry]] = Try { // We have to wrap in a BufferedInputStream because this method // only takes InputStreams that support the `mark()` method. new ArchiveStreamFactory() .createArchiveInputStream(new BufferedInputStream(inputStream)) - .asInstanceOf[ArchiveInputStream] + .asInstanceOf[ArchiveInputStream[ArchiveEntry]] } match { case Success(stream) => Right(stream) case Failure(err: ArchiveException) => Left(ArchiveFormatError(err)) diff --git a/bag_unpacker/src/test/scala/weco/storage_service/bag_unpacker/fixtures/CompressFixture.scala b/bag_unpacker/src/test/scala/weco/storage_service/bag_unpacker/fixtures/CompressFixture.scala index fe83e74ae..e44e1d49a 100644 --- a/bag_unpacker/src/test/scala/weco/storage_service/bag_unpacker/fixtures/CompressFixture.scala +++ b/bag_unpacker/src/test/scala/weco/storage_service/bag_unpacker/fixtures/CompressFixture.scala @@ -2,16 +2,9 @@ package weco.storage_service.bag_unpacker.fixtures import java.io.{File, _} import grizzled.slf4j.Logging -import org.apache.commons.compress.archivers.{ - ArchiveEntry, - ArchiveOutputStream, - ArchiveStreamFactory -} -import org.apache.commons.compress.compressors.{ - CompressorOutputStream, - CompressorStreamFactory -} import org.apache.commons.io.IOUtils +import org.apache.commons.compress.archivers.{ArchiveEntry, ArchiveOutputStream, ArchiveStreamFactory} +import org.apache.commons.compress.compressors.{CompressorOutputStream, CompressorStreamFactory} import org.scalatest.matchers.should.Matchers import weco.fixtures.TestWith import weco.storage_service.generators.StorageRandomGenerators @@ -146,6 +139,7 @@ trait CompressFixture[BagLocation <: Location, Namespace] def finish(): Unit = { archiveOutputStream.flush() archiveOutputStream.finish() + archiveOutputStream.close() compressorOutputStream.flush() compressorOutputStream.close() } @@ -182,7 +176,7 @@ trait CompressFixture[BagLocation <: Location, Namespace] compressorName: String )( outputStream: OutputStream - ): CompressorOutputStream = { + ): CompressorOutputStream[BufferedOutputStream] = { val compressorStreamFactory = new CompressorStreamFactory() @@ -195,13 +189,13 @@ trait CompressFixture[BagLocation <: Location, Namespace] compressorName, bufferedOutputStream ) - } + }.asInstanceOf[CompressorOutputStream[BufferedOutputStream]] private def packer( archiverName: String )( outputStream: OutputStream - ): ArchiveOutputStream = { + ): ArchiveOutputStream[ArchiveEntry] = { val archiveStreamFactory = new ArchiveStreamFactory() diff --git a/project/Dependencies.scala b/project/Dependencies.scala index ff21256ad..6d1dcb91d 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -83,7 +83,7 @@ object ExternalDependencies { lazy val versions = new { val azure = "12.25.4" - val commonsCompress = "1.5" + val commonsCompress = "1.27.1" val commonsIO = "2.17.0" val mockito = "5.13.0" val scalatest = "3.2.19"