From 37567262f535de5933c190ace79f63ca6d96d6d6 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 20 May 2020 20:20:33 +0200 Subject: [PATCH] Ignore FileSystemException-s when deleting temporary launcher on Windows (#23) --- core/src/main/scala/ammrunner/AmmoniteFetcher.scala | 8 ++++++-- core/src/main/scala/ammrunner/Command.scala | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/main/scala/ammrunner/AmmoniteFetcher.scala b/core/src/main/scala/ammrunner/AmmoniteFetcher.scala index 8f4119f..030b925 100644 --- a/core/src/main/scala/ammrunner/AmmoniteFetcher.scala +++ b/core/src/main/scala/ammrunner/AmmoniteFetcher.scala @@ -2,7 +2,7 @@ package ammrunner import java.io.{File, InputStream, OutputStream} import java.nio.charset.{Charset, StandardCharsets} -import java.nio.file.{Files, Path} +import java.nio.file.{Files, FileSystemException, Path} import coursierapi.{Cache, Dependency, Fetch, Logger, ResolutionParams} import coursier.launcher.{BootstrapGenerator, ClassLoaderContent, ClassPathEntry} @@ -127,7 +127,11 @@ import scala.io.{BufferedSource, Codec} new Thread { setDaemon(true) override def run(): Unit = - Files.deleteIfExists(tmpFile) + try Files.deleteIfExists(tmpFile) + catch { + case e: FileSystemException if Command.isWindows => + System.err.println(s"Error deleting $tmpFile: $e") + } } ) BootstrapGenerator.generate(params, tmpFile) diff --git a/core/src/main/scala/ammrunner/Command.scala b/core/src/main/scala/ammrunner/Command.scala index 2517b34..f6fb478 100644 --- a/core/src/main/scala/ammrunner/Command.scala +++ b/core/src/main/scala/ammrunner/Command.scala @@ -30,7 +30,7 @@ import scala.annotation.tailrec object Command { - private lazy val isWindows: Boolean = + private[ammrunner] lazy val isWindows: Boolean = Option(System.getProperty("os.name")) .map(_.toLowerCase(Locale.ROOT)) .exists(_.contains("windows"))