Prevent race condition while reading uuid

This commit is contained in:
Mygod
2021-05-30 19:30:58 -04:00
parent ecf6808f4d
commit afa80add94

View File

@@ -146,7 +146,9 @@ class RootServer {
try { try {
val token2 = UUID.randomUUID().toString() val token2 = UUID.randomUUID().toString()
val persistence = File(context.codeCacheDir, ".librootkotlinx-uuid") val persistence = File(context.codeCacheDir, ".librootkotlinx-uuid")
val uuid = context.packageName + '@' + if (persistence.canRead()) persistence.readText() else { val uuid = context.packageName + '@' + try {
persistence.readText()
} catch (_: FileNotFoundException) {
UUID.randomUUID().toString().also { persistence.writeText(it) } UUID.randomUUID().toString().also { persistence.writeText(it) }
} }
val (script, relocated) = AppProcess.relocateScript(uuid) val (script, relocated) = AppProcess.relocateScript(uuid)