Skip to content

Commit

Permalink
Fix FileAlreadyExistsException when copying jars into the instance cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jjudd committed Dec 6, 2024
1 parent fc21209 commit aba4fa5
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package workers.common
import xsbti.compile.ScalaInstance
import java.io.File
import java.net.URLClassLoader
import java.nio.file.{Files, Path, Paths}
import java.nio.file.{FileAlreadyExistsException, Files, Path, Paths}
import java.util.Properties
import java.util.concurrent.ConcurrentHashMap
import scala.collection.immutable.TreeMap
Expand Down Expand Up @@ -110,8 +110,14 @@ object AnnexScalaInstance {
// Copying a file is not atomic, so we don't want to end up in a funky state where two
// copies of the same file happen at the same time and cause something bad to happen.
if (!Files.exists(workerJar)) {
Files.createDirectories(workerJar.getParent())
Files.copy(workRequestJar, workerJar)
try {
Files.createDirectories(workerJar.getParent())
Files.copy(workRequestJar, workerJar)
} catch {
// We do not care if the file already exists
case e: FileAlreadyExistsException => {}
case e: Throwable => throw new Exception("Error adding file to instance cache", e)
}
}
}
}
Expand Down

0 comments on commit aba4fa5

Please sign in to comment.