From a92bc6fcb9f54f4afaf63f4904f588453d18181b Mon Sep 17 00:00:00 2001 From: Henry Genet Date: Fri, 15 Mar 2024 23:59:30 +0100 Subject: [PATCH 1/2] Foolproof 'assemblyOutputPath' --- src/main/scala/sbtassembly/Assembly.scala | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/scala/sbtassembly/Assembly.scala b/src/main/scala/sbtassembly/Assembly.scala index def667b..bc3c671 100644 --- a/src/main/scala/sbtassembly/Assembly.scala +++ b/src/main/scala/sbtassembly/Assembly.scala @@ -347,8 +347,15 @@ object Assembly { .getOrElse(System.currentTimeMillis()) timed(Level.Debug, "Create jar") { - IO.delete(output) - createJar(output, jarEntriesToWrite, jarManifest, localTime) + if (output.isDirectory) { + val invalidPath = output.toPath.toAbsolutePath.normalize + log.error(s"Attempted to overwrite existing directory: $invalidPath") + log.error("Update 'assemblyOutputPath' key or manually delete the corresponding path.") + throw new RuntimeException("Exiting task") + } else { + IO.delete(output) + createJar(output, jarEntriesToWrite, jarManifest, localTime) + } } val fullSha1 = timed(Level.Debug, "Hash newly-built Jar") { hash(output) From 09b2817c55d9be0a32e35533eef87bb68ec28e2a Mon Sep 17 00:00:00 2001 From: Henry Date: Sat, 16 Mar 2024 15:49:23 +0100 Subject: [PATCH 2/2] Update src/main/scala/sbtassembly/Assembly.scala Co-authored-by: eugene yokota --- src/main/scala/sbtassembly/Assembly.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/scala/sbtassembly/Assembly.scala b/src/main/scala/sbtassembly/Assembly.scala index bc3c671..58732b1 100644 --- a/src/main/scala/sbtassembly/Assembly.scala +++ b/src/main/scala/sbtassembly/Assembly.scala @@ -349,8 +349,7 @@ object Assembly { timed(Level.Debug, "Create jar") { if (output.isDirectory) { val invalidPath = output.toPath.toAbsolutePath.normalize - log.error(s"Attempted to overwrite existing directory: $invalidPath") - log.error("Update 'assemblyOutputPath' key or manually delete the corresponding path.") + log.error(s"expected a file name for assemblyOutputPath, but found a directory: ${invalidPath}; fix the setting or delete the directory") throw new RuntimeException("Exiting task") } else { IO.delete(output)