Skip to content

Commit

Permalink
Fix for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
thesamet committed Jan 20, 2024
1 parent 92138f5 commit d2f26a4
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions bridge/src/main/scala/protocbridge/FileCache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scala.concurrent.Promise
import java.io.File
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.Try
import java.nio.file.{Files, Path, StandardCopyOption}
import java.nio.file.{AccessDeniedException, Files, Path, StandardCopyOption}

/** Cache for files that performs a single concurrent get per key upon miss. */
final class FileCache[K](
Expand Down Expand Up @@ -50,12 +50,22 @@ final class FileCache[K](
val dstPath = dst.toPath()
Files.copy(src.toPath(), tmp.toPath(), StandardCopyOption.REPLACE_EXISTING)
tmp.setExecutable(true)
Files.move(
tmp.toPath(),
dstPath,
StandardCopyOption.ATOMIC_MOVE,
StandardCopyOption.REPLACE_EXISTING
)
try {
Files.move(
tmp.toPath(),
dstPath,
StandardCopyOption.ATOMIC_MOVE,
StandardCopyOption.REPLACE_EXISTING
)
} catch {
case e: AccessDeniedException =>
// On Windows sometimes atomic moves are impossible...
Files.move(
tmp.toPath(),
dstPath,
StandardCopyOption.REPLACE_EXISTING
)
}
dst
}

Expand Down

0 comments on commit d2f26a4

Please sign in to comment.