Native: Use NIO Files.createTemp*() in favor of File.createTemp*() extension functions

This commit is contained in:
Dmitriy Dolovov
2020-11-11 13:11:23 +03:00
parent 47e2656ca9
commit ee7f3b1bfe
2 changed files with 13 additions and 13 deletions
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.konan.properties.resolvablePropertyString
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.konan.util.DependencyDirectories
import java.nio.file.Files
import java.util.*
private val Project.jvmArgs
@@ -127,7 +128,7 @@ internal class KotlinNativeCompilerRunner(project: Project) : KotlinNativeToolRu
override fun transformArgs(args: List<String>): List<String> {
if (!useArgFile) return super.transformArgs(args)
val argFile = createTempFile(prefix = "kotlinc-native-args", suffix = ".lst").apply { deleteOnExit() }
val argFile = Files.createTempFile(/* prefix = */ "kotlinc-native-args", /* suffix = */ ".lst").toFile().apply { deleteOnExit() }
argFile.printWriter().use { w ->
args.forEach { arg ->
val escapedArg = arg
@@ -105,11 +105,10 @@ internal data class CommonizerTaskParams(
val parentDir = destinationDir.parentFile
parentDir.mkdirs()
val destinationTmpDir = createTempDir(
prefix = "tmp-" + destinationDir.name,
suffix = ".new",
directory = parentDir
)
val destinationTmpDir = Files.createTempDirectory(
/* dir = */ parentDir.toPath(),
/* prefix = */ "tmp-new-" + destinationDir.name
).toFile()
commandLineArguments += "native-dist-commonize"
commandLineArguments += "-distribution-path"
@@ -256,16 +255,16 @@ private fun renameToTempAndDelete(directory: File) {
directory
} else {
// first, rename the directory to some temp directory
val tempDir = createTempFile(
prefix = "tmp-" + directory.name,
suffix = ".old",
directory = directory.parentFile
val tempDir = Files.createTempFile(
/* dir = */ directory.parentFile.toPath(),
/* prefix = */ "tmp-old-" + directory.name,
/* suffix = */ null
)
tempDir.delete()
Files.delete(tempDir)
Files.move(directory.toPath(), tempDir.toPath(), StandardCopyOption.ATOMIC_MOVE)
Files.move(directory.toPath(), tempDir, StandardCopyOption.ATOMIC_MOVE)
tempDir
tempDir.toFile()
}
dirToRemove.deleteRecursively()