Skip to content

Commit e4d55ed

Browse files
ptarjanjohnynek
authored andcommitted
Handle FileAlreadyExistsException in ScalaPBGenerator (#789)
1 parent d9c6da6 commit e4d55ed

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/scala/scripts/ScalaPBGenerator.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scripts
22

33
import java.io.PrintStream
4-
import java.nio.file.Path
4+
import java.nio.file.{Path, FileAlreadyExistsException}
55

66
import io.bazel.rulesscala.io_utils.DeleteRecursively
77
import io.bazel.rulesscala.jar.JarCreator
@@ -12,6 +12,7 @@ import scalapb.ScalaPbCodeGenerator
1212
import java.nio.file.{Files, Paths}
1313
import scalapb.{ScalaPBC, ScalaPbCodeGenerator, ScalaPbcException}
1414
import java.net.URLClassLoader
15+
import scala.util.{Try, Failure}
1516

1617
object ScalaPBWorker extends GenericWorker(new ScalaPBGenerator) {
1718

@@ -39,7 +40,12 @@ class ScalaPBGenerator extends Processor {
3940
val relativePath = root.relativize(fullPath)
4041

4142
relativePath.toFile.getParentFile.mkdirs
42-
Files.copy(fullPath, relativePath)
43+
Try(Files.copy(fullPath, relativePath)) match {
44+
case Failure(err: FileAlreadyExistsException) =>
45+
Console.println(s"File already exists, skipping: ${err.getMessage}")
46+
case Failure(err) => throw err
47+
case _ => ()
48+
}
4349
}
4450
}
4551
def deleteDir(path: Path): Unit =

0 commit comments

Comments
 (0)