Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling in ZIP utilities #1290

Merged
merged 1 commit into from
Dec 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh for Java's try-with-resources.

zipOut.close()
}
}
Expand Down