Skip to content

Commit

Permalink
Make processDependencyJars synchronized to avoid possible issues acti…
Browse files Browse the repository at this point in the history
…ng on the same jar files
  • Loading branch information
er1c committed Oct 18, 2021
1 parent b0b7915 commit 114ad3f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
28 changes: 25 additions & 3 deletions src/main/scala/sbtassembly/Assembly.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/sbtassembly/AssemblyUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 114ad3f

Please sign in to comment.