Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use NIO to create temp file #344

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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