Skip to content

Commit

Permalink
Merge pull request #344 from eed3si9n/wip/temp
Browse files Browse the repository at this point in the history
Use NIO to create temp file
  • Loading branch information
eed3si9n authored May 12, 2023
2 parents 1e0c451 + 30c634a commit a3f7892
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion io/src/main/scala/sbt/internal/io/Milli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions io/src/main/scala/sbt/io/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(); ()
}
}

Expand Down

0 comments on commit a3f7892

Please sign in to comment.