Skip to content

Commit

Permalink
Handle FileAlreadyExistsException in ScalaPBGenerator (#789)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptarjan authored and johnynek committed Jul 18, 2019
1 parent d9c6da6 commit e4d55ed
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/scala/scripts/ScalaPBGenerator.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package scripts

import java.io.PrintStream
import java.nio.file.Path
import java.nio.file.{Path, FileAlreadyExistsException}

import io.bazel.rulesscala.io_utils.DeleteRecursively
import io.bazel.rulesscala.jar.JarCreator
Expand All @@ -12,6 +12,7 @@ import scalapb.ScalaPbCodeGenerator
import java.nio.file.{Files, Paths}
import scalapb.{ScalaPBC, ScalaPbCodeGenerator, ScalaPbcException}
import java.net.URLClassLoader
import scala.util.{Try, Failure}

object ScalaPBWorker extends GenericWorker(new ScalaPBGenerator) {

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

relativePath.toFile.getParentFile.mkdirs
Files.copy(fullPath, relativePath)
Try(Files.copy(fullPath, relativePath)) match {
case Failure(err: FileAlreadyExistsException) =>
Console.println(s"File already exists, skipping: ${err.getMessage}")
case Failure(err) => throw err
case _ => ()
}
}
}
def deleteDir(path: Path): Unit =
Expand Down

0 comments on commit e4d55ed

Please sign in to comment.