Skip to content

Commit

Permalink
protobuf module: fix truncation issue when unpacking (#2800)
Browse files Browse the repository at this point in the history
It is possible that unpacked files from the classpath share the same
name but not the same content. In case an existing unpacked file is
replaced by a shorter file, it needs to be properly truncated lest the
result be garbage.

A warning messages is logged when a proto file gets overwritten.

Pull request: #2800

Co-authored-by: Tobias Roeser <[email protected]>
  • Loading branch information
jodersky and lefou authored Oct 1, 2023
1 parent f0b423e commit b95cf46
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ trait ScalaPBModule extends ScalaModule {
case Some(entry) =>
if (entry.getName.endsWith(".proto")) {
val protoDest = dest / os.SubPath(entry.getName)
Using(os.write.outputStream(protoDest, createFolders = true))(IO.stream(zip, _))
if (os.exists(protoDest))
T.log.error(s"Warning: Overwriting ${dest} / ${os.SubPath(entry.getName)} ...")
Using.resource(os.write.over.outputStream(protoDest, createFolders = true)) { os =>
IO.stream(zip, os)
}
}
zip.closeEntry()
true
Expand Down

0 comments on commit b95cf46

Please sign in to comment.