From 77be6cd0f8f4267039b094cae820af6a3f051e40 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Sat, 30 Sep 2023 09:30:24 +0200 Subject: [PATCH 1/5] protobuf module: fix truncation issue when unpacking 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. --- .../scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala b/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala index 85b978d1725..77b70bf3847 100644 --- a/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala +++ b/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala @@ -104,7 +104,7 @@ 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, _)) + Using(os.write.over.outputStream(protoDest, createFolders = true))(IO.stream(zip, _)) } zip.closeEntry() true From 970bc2f60fdce00bb17f7b9be22e72abd4c21c36 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Sat, 30 Sep 2023 09:51:56 +0200 Subject: [PATCH 2/5] format --- .../src/mill/contrib/scalapblib/ScalaPBModule.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala b/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala index 77b70bf3847..b05ad56d7dd 100644 --- a/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala +++ b/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala @@ -104,7 +104,10 @@ trait ScalaPBModule extends ScalaModule { case Some(entry) => if (entry.getName.endsWith(".proto")) { val protoDest = dest / os.SubPath(entry.getName) - Using(os.write.over.outputStream(protoDest, createFolders = true))(IO.stream(zip, _)) + Using(os.write.over.outputStream(protoDest, createFolders = true))(IO.stream( + zip, + _ + )) } zip.closeEntry() true From 2ca855bd1a0d71aa7740ab923e100ea5b482531b Mon Sep 17 00:00:00 2001 From: jodersky Date: Sat, 30 Sep 2023 10:22:07 +0200 Subject: [PATCH 3/5] Update contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala Co-authored-by: Tobias Roeser --- .../src/mill/contrib/scalapblib/ScalaPBModule.scala | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala b/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala index b05ad56d7dd..15a63f7dafb 100644 --- a/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala +++ b/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala @@ -104,10 +104,9 @@ trait ScalaPBModule extends ScalaModule { case Some(entry) => if (entry.getName.endsWith(".proto")) { val protoDest = dest / os.SubPath(entry.getName) - Using(os.write.over.outputStream(protoDest, createFolders = true))(IO.stream( - zip, - _ - )) + Using.resource(os.write.over.outputStream(protoDest, createFolders = true)) { os => + IO.stream(zip, os) + }``` } zip.closeEntry() true From d6ca1f2c6339f638f1ca3d9b85e9b02cca6be113 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Sat, 30 Sep 2023 11:55:37 +0200 Subject: [PATCH 4/5] Fix compile error --- .../scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala b/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala index 15a63f7dafb..0e9001e67bc 100644 --- a/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala +++ b/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala @@ -106,7 +106,7 @@ trait ScalaPBModule extends ScalaModule { val protoDest = dest / os.SubPath(entry.getName) Using.resource(os.write.over.outputStream(protoDest, createFolders = true)) { os => IO.stream(zip, os) - }``` + } } zip.closeEntry() true From 8e4e641153d5d71bb60a029b8eecc259fd877e9f Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Sun, 1 Oct 2023 09:05:19 +0200 Subject: [PATCH 5/5] Log a warning when proto files get overwritten --- .../scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala b/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala index 0e9001e67bc..c7b535283ca 100644 --- a/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala +++ b/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala @@ -104,6 +104,8 @@ trait ScalaPBModule extends ScalaModule { case Some(entry) => if (entry.getName.endsWith(".proto")) { val protoDest = dest / os.SubPath(entry.getName) + 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) }