Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.0.0-BETA31

* Added helpers for Attachment syncing.
* Fix loading native PowerSync extension for Java targets.

## 1.0.0-BETA30

Expand Down
25 changes: 17 additions & 8 deletions core/src/jvmMain/kotlin/com/powersync/ExtractLib.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.powersync

import java.io.File
import java.util.UUID

private class R

Expand All @@ -21,14 +22,22 @@ internal fun extractLib(fileName: String): String {
else -> error("Unsupported architecture: $sysArch")
}

val path = "/$prefix${fileName}_$arch.$extension"
val suffix = UUID.randomUUID().toString()
val file =
File(System.getProperty("java.io.tmpdir"), "$prefix$fileName-$suffix.$extension").apply {
setReadable(true)
setWritable(true)
setExecutable(true)

val resourceURI =
(R::class.java.getResource(path) ?: error("Resource $path not found"))
deleteOnExit()
}

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

(R::class.java.getResourceAsStream(resourcePath) ?: error("Resource $resourcePath not found")).use { input ->
file.outputStream().use { output -> input.copyTo(output) }
}

// Wrapping the above in a File handle resolves the URI to a path usable by SQLite.
// This is particularly relevant on Windows.
// On Windows [resourceURI.path] starts with a `/`, e.g. `/c:/...`. SQLite does not load this path correctly.
// The wrapping here transforms the path to `c:/...` which does load correctly.
return File(resourceURI.path).path.toString()
println("PowerSync loadable should be at $file")
return file.absolutePath
}