From 3849354df2155ad6d251ff0ea8c101e989fa0f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Brychta?= Date: Mon, 7 Oct 2024 08:38:40 +0100 Subject: [PATCH] Update commons compress --- .../bag_unpacker/services/Unpacker.scala | 2 +- .../bag_unpacker/storage/Unarchiver.scala | 6 +++--- .../fixtures/CompressFixture.scala | 18 ++++++----------- project/Dependencies.scala | 20 +++++++++---------- 4 files changed, 20 insertions(+), 26 deletions(-) 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 3a877b4003..2120e64128 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 35ed859a23..423ab5a71b 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 fe83e74ae3..e44e1d49a5 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 ff21256adf..8d8cd905fd 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -2,15 +2,15 @@ import sbt._ object WellcomeDependencies { lazy val versions = new { - val typesafe = "32.43.1" - val fixtures = "32.43.1" - val http = "32.43.1" - val json = "32.43.1" - val messaging = "32.43.1" - val monitoring = "32.43.1" - val storage = "32.43.1" - val elasticsearch = "32.43.1" - val sierra = "32.43.1" + val typesafe = "32.44.0-SNAPSHOT" + val fixtures = "32.44.0-SNAPSHOT" + val http = "32.44.0-SNAPSHOT" + val json = "32.44.0-SNAPSHOT" + val messaging = "32.44.0-SNAPSHOT" + val monitoring = "32.44.0-SNAPSHOT" + val storage = "32.44.0-SNAPSHOT" + val elasticsearch = "32.44.0-SNAPSHOT" + val sierra = "32.44.0-SNAPSHOT" } val jsonLibrary: Seq[ModuleID] = Seq( @@ -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"