Skip to content

Commit 61a5617

Browse files
committed
Fix extracting PowerSync library from JAR
1 parent 5f32d69 commit 61a5617

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 1.0.0-BETA31
44

55
* Added helpers for Attachment syncing.
6+
* Fix loading native PowerSync extension for Java targets.
67

78
## 1.0.0-BETA30
89

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.powersync
22

33
import java.io.File
4+
import java.nio.file.Files
5+
import java.nio.file.Path
6+
import kotlin.io.path.Path
7+
import kotlin.io.path.absolutePathString
48

59
private class R
610

@@ -21,14 +25,20 @@ internal fun extractLib(fileName: String): String {
2125
else -> error("Unsupported architecture: $sysArch")
2226
}
2327

24-
val path = "/$prefix${fileName}_$arch.$extension"
28+
val path = Files.createTempFile(Path(System.getProperty("java.io.tmpdir")), prefix, extension)
29+
val file = path.toFile().apply {
30+
setReadable(true)
31+
setWritable(true)
32+
setExecutable(true)
2533

26-
val resourceURI =
27-
(R::class.java.getResource(path) ?: error("Resource $path not found"))
34+
deleteOnExit()
35+
}
2836

29-
// Wrapping the above in a File handle resolves the URI to a path usable by SQLite.
30-
// This is particularly relevant on Windows.
31-
// On Windows [resourceURI.path] starts with a `/`, e.g. `/c:/...`. SQLite does not load this path correctly.
32-
// The wrapping here transforms the path to `c:/...` which does load correctly.
33-
return File(resourceURI.path).path.toString()
37+
val resourcePath = "/$prefix${fileName}_$arch.$extension"
38+
39+
(R::class.java.getResourceAsStream(resourcePath) ?: error("Resource $path not found")).use { input ->
40+
file.outputStream().use { output -> input.copyTo(output) }
41+
}
42+
43+
return path.absolutePathString()
3444
}

0 commit comments

Comments
 (0)