|
|
@ -107,13 +107,10 @@ public inline fun <T> Path.useTempFile( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public inline fun <T> Path.atomicWrite(f: (Path) -> T): T { |
|
|
|
public inline fun <T> Path.atomicWrite(f: (Path) -> T): T { |
|
|
|
val tempFile = Files.createTempFile(parent, ".$fileName", ".tmp") |
|
|
|
parent.useTempFile(".$fileName", ".tmp") { tempFile -> |
|
|
|
try { |
|
|
|
|
|
|
|
val result = f(tempFile) |
|
|
|
val result = f(tempFile) |
|
|
|
Files.move(tempFile, this, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING) |
|
|
|
Files.move(tempFile, this, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING) |
|
|
|
return result |
|
|
|
return result |
|
|
|
} finally { |
|
|
|
|
|
|
|
Files.deleteIfExists(tempFile) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|