Skip to content

Commit ceef5c1

Browse files
authored
Merge pull request #75 from lucidsoftware/fix-file-already-exists-exception
Fix FileAlreadyExistsException when copying jars into the instance cache
2 parents fc21209 + 3f592d9 commit ceef5c1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main/scala/higherkindness/rules_scala/workers/common/AnnexScalaInstance.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package workers.common
44
import xsbti.compile.ScalaInstance
55
import java.io.File
66
import java.net.URLClassLoader
7-
import java.nio.file.{Files, Path, Paths}
7+
import java.nio.file.{FileAlreadyExistsException, Files, Path, Paths}
88
import java.util.Properties
99
import java.util.concurrent.ConcurrentHashMap
1010
import scala.collection.immutable.TreeMap
@@ -110,8 +110,14 @@ object AnnexScalaInstance {
110110
// Copying a file is not atomic, so we don't want to end up in a funky state where two
111111
// copies of the same file happen at the same time and cause something bad to happen.
112112
if (!Files.exists(workerJar)) {
113-
Files.createDirectories(workerJar.getParent())
114-
Files.copy(workRequestJar, workerJar)
113+
try {
114+
Files.createDirectories(workerJar.getParent())
115+
Files.copy(workRequestJar, workerJar)
116+
} catch {
117+
// We do not care if the file already exists
118+
case _: FileAlreadyExistsException => {}
119+
case e: Throwable => throw new Exception("Error adding file to instance cache", e)
120+
}
115121
}
116122
}
117123
}

0 commit comments

Comments
 (0)