Skip to content

Commit

Permalink
Improve error handling in ZIP utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
retronym committed Dec 11, 2019
1 parent e477508 commit ea173c4
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/main/scala/com/typesafe/sbt/packager/universal/ZipHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,17 @@ object ZipHelper {
// Now check to see if we have permissions for this sucker.
mode foreach (entry.setUnixMode)
output putArchiveEntry entry
// TODO - Write file into output?
IOUtils.copy(new java.io.FileInputStream(file), output)
output.closeArchiveEntry()
val fis = new java.io.FileInputStream(file)
try {
try {
// TODO - Write file into output?
IOUtils.copy(fis, output)
} finally {
output.closeArchiveEntry()
}
} finally {
fis.close()
}
}
}
}
Expand All @@ -126,7 +134,13 @@ object ZipHelper {
private def withZipOutput(file: File)(f: ZipArchiveOutputStream => Unit): Unit = {
val zipOut = new ZipArchiveOutputStream(file)
zipOut setLevel Deflater.BEST_COMPRESSION
try { f(zipOut) } finally {
try {
f(zipOut)
} catch {
case t: Throwable =>
IOUtils.closeQuietly(zipOut)
throw t
} finally {
zipOut.close()
}
}
Expand Down

0 comments on commit ea173c4

Please sign in to comment.