Skip to content

Commit 1b4f282

Browse files
committed
Check path format
1 parent 6f90618 commit 1b4f282

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

core/src/jvmMain/kotlin/com/powersync/ExtractLib.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.powersync
22

3+
import java.io.File
34
import java.nio.file.Files
45
import java.nio.file.Path
6+
import java.util.UUID
57
import kotlin.io.path.Path
68
import kotlin.io.path.absolutePathString
9+
import kotlin.uuid.Uuid
710

811
private class R
912

@@ -24,21 +27,22 @@ internal fun extractLib(fileName: String): String {
2427
else -> error("Unsupported architecture: $sysArch")
2528
}
2629

27-
val path = Files.createTempFile(Path(System.getProperty("java.io.tmpdir")), "$prefix$fileName", extension)
28-
val file =
29-
path.toFile().apply {
30-
setReadable(true)
31-
setWritable(true)
32-
setExecutable(true)
30+
val suffix = UUID.randomUUID().toString()
31+
val file = File(System.getProperty("java.io.tmpdir"), "$prefix$fileName-$suffix.$extension").apply {
32+
setReadable(true)
33+
setWritable(true)
34+
setExecutable(true)
35+
36+
deleteOnExit()
37+
}
3338

34-
deleteOnExit()
35-
}
3639

3740
val resourcePath = "/$prefix${fileName}_$arch.$extension"
3841

39-
(R::class.java.getResourceAsStream(resourcePath) ?: error("Resource $path not found")).use { input ->
42+
(R::class.java.getResourceAsStream(resourcePath) ?: error("Resource $resourcePath not found")).use { input ->
4043
file.outputStream().use { output -> input.copyTo(output) }
4144
}
4245

43-
return path.absolutePathString()
46+
println("PowerSync loadable should be at $file")
47+
return file.absolutePath
4448
}

0 commit comments

Comments
 (0)