From 30c634a6c10fb2eee02df359c9ee3d51a70b792c Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Thu, 11 May 2023 22:52:38 -0400 Subject: [PATCH] Use NIO to create temp file --- io/src/main/scala/sbt/internal/io/Milli.scala | 3 ++- io/src/main/scala/sbt/io/IO.scala | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/io/src/main/scala/sbt/internal/io/Milli.scala b/io/src/main/scala/sbt/internal/io/Milli.scala index 4d8f1dc4..fe2e4750 100644 --- a/io/src/main/scala/sbt/internal/io/Milli.scala +++ b/io/src/main/scala/sbt/internal/io/Milli.scala @@ -12,6 +12,7 @@ package sbt.internal.io import java.io.{ File, FileNotFoundException, IOException } import java.nio.{ ByteBuffer, ByteOrder } +import java.nio.file.Files import java.util.Date import com.sun.jna.platform.win32.Kernel32 @@ -396,7 +397,7 @@ object Milli { if (jdkTimestamps) None else { - val file = File.createTempFile("sbt.io.Milli", "test-file", projectDir) + val file = Files.createTempFile(projectDir.toPath(), "sbt.io.Milli", "test-file").toFile try { val originalTime = getModifiedTime(file) setModifiedTime(file, originalTime - 27) diff --git a/io/src/main/scala/sbt/io/IO.scala b/io/src/main/scala/sbt/io/IO.scala index 69b9d40b..edb8ca46 100644 --- a/io/src/main/scala/sbt/io/IO.scala +++ b/io/src/main/scala/sbt/io/IO.scala @@ -526,11 +526,11 @@ object IO { def withTemporaryFile[T](prefix: String, postfix: String, keepFile: Boolean)( action: File => T ): T = { - val file = File.createTempFile(prefix, postfix) + val file = Files.createTempFile(prefix, postfix) try { - action(file) + action(file.toFile()) } finally { - if (!keepFile) file.delete(); () + if (!keepFile) file.toFile().delete(); () } }