From 114ad3fdd58d3457b67f1d8dfb3c26380d47338e Mon Sep 17 00:00:00 2001 From: Eric Peters Date: Mon, 18 Oct 2021 14:08:12 -0700 Subject: [PATCH] Make processDependencyJars synchronized to avoid possible issues acting on the same jar files --- src/main/scala/sbtassembly/Assembly.scala | 28 +++++++++++++++++-- .../scala/sbtassembly/AssemblyUtils.scala | 4 +-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/scala/sbtassembly/Assembly.scala b/src/main/scala/sbtassembly/Assembly.scala index d305b7e7..25ca915b 100644 --- a/src/main/scala/sbtassembly/Assembly.scala +++ b/src/main/scala/sbtassembly/Assembly.scala @@ -228,8 +228,21 @@ object Assembly { ): Vector[MappingSet] = { val assemblyDir = ao.assemblyDirectory.get val assemblyUnzipDir = ao.assemblyUnzipDirectory.getOrElse(assemblyDir) + val projectIdMsg: String = getProjectIdMsg(state) + + if (!ao.cacheOutput && assemblyDir.exists) { + log.info(s"AssemblyOption.cacheOutput set to false, deleting assemblyDirectory: $assemblyDir for project: $projectIdMsg") + IO.delete(assemblyDir) + } - if (!ao.cacheUnzip) ao.assemblyUnzipDirectory.foreach{ IO.delete } + for { + unzipDir <- ao.assemblyUnzipDirectory + if !ao.cacheUnzip + if unzipDir.exists + } { + log.info(s"AssemblyOption.cacheUnzip set to false, deleting assemblyUnzipDirectory: $unzipDir for project: $projectIdMsg") + IO.delete(unzipDir) + } if (!assemblyDir.exists) IO.createDirectory(assemblyDir) if (!assemblyUnzipDir.exists) IO.createDirectory(assemblyUnzipDir) @@ -391,7 +404,7 @@ object Assembly { isCacheOnly: Boolean, log: Logger, state: State - ): ParVector[(File, File)] = { + ): ParVector[(File, File)] = synchronized { val defaultAssemblyDir = assemblyOption.assemblyDirectory.get val assemblyUnzipDir: File = assemblyOption.assemblyUnzipDirectory.getOrElse(defaultAssemblyDir) @@ -467,10 +480,19 @@ object Assembly { // Unzip into cache dir and copy over } else if (assemblyOption.cacheUnzip && jarNameFinalPath != jarNameCachePath) { IO.delete(jarCacheDir) + IO.delete(jarOutputDir) + IO.createDirectory(jarCacheDir) + IO.createDirectory(jarOutputDir) log.info("Unzipping %s into unzip cache: %s for project: %s".format(jarName, jarCacheDir, projectIdMsg)) - AssemblyUtils.unzip(jar, jarCacheDir, log) + val files = AssemblyUtils.unzip(jar, jarCacheDir, log) + + // TODO: This is kind of a hack, but doing it seems to prevent a docker file system issue preventing + // FileNotFound exception after unzipping + files.foreach { f => + assert(f.exists(), s"File $f not found after unzipping $jar into $jarCacheDir!") + } if (useHardLinks) log.info("Creating hardlinks of %s from unzip cache: %s, to: %s, for project: %s".format(jarName, jarCacheDir, jarOutputDir, projectIdMsg)) else log.info("Copying %s from unzip cache: %s, to: %s, for project: %s".format(jarName, jarCacheDir, jarOutputDir, projectIdMsg)) diff --git a/src/main/scala/sbtassembly/AssemblyUtils.scala b/src/main/scala/sbtassembly/AssemblyUtils.scala index 00a3cf12..7c2719a4 100644 --- a/src/main/scala/sbtassembly/AssemblyUtils.scala +++ b/src/main/scala/sbtassembly/AssemblyUtils.scala @@ -171,9 +171,9 @@ private[sbtassembly] object AssemblyUtils { hardLink: Boolean )(from: File, to: File): File = { if (overwrite || !to.exists || IO.getModifiedTimeOrZero(from) > IO.getModifiedTimeOrZero(to)) { - if (from.isDirectory) + if (from.isDirectory) { IO.createDirectory(to) - else { + } else { IO.createDirectory(to.getParentFile) copyFile(from, to, preserveLastModified, preserveExecutable, hardLink) }