Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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-BETA29 (unreleased)

* Fix potential race condition between jobs in `connect()` and `disconnect()`.
* [JVM Windows] Fixed PowerSync Extension temporary file deletion error on process shutdown.

## 1.0.0-BETA28

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public actual class DatabaseDriverFactory {
}

public companion object {
private val powersyncExtension: String = extractLib("powersync").toString()
private val powersyncExtension: String = extractLib("powersync")
}
}
23 changes: 9 additions & 14 deletions core/src/jvmMain/kotlin/com/powersync/ExtractLib.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.powersync

import java.nio.file.Path
import kotlin.io.path.createTempFile
import kotlin.io.path.deleteIfExists
import kotlin.io.path.outputStream
import java.io.File

private class R

internal fun extractLib(fileName: String): Path {
internal fun extractLib(fileName: String): String {
val os = System.getProperty("os.name").lowercase()
val (prefix, extension) =
when {
Expand All @@ -26,14 +23,12 @@ internal fun extractLib(fileName: String): Path {

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

val tmpPath = createTempFile("$prefix$fileName", ".$extension")
Runtime.getRuntime().addShutdownHook(Thread { tmpPath.deleteIfExists() })
val resourceURI =
(R::class.java.getResource(path) ?: error("Resource $path not found"))

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

return tmpPath
/**
* Wrapping in a File handle resolves the URI to a path usable by SQLite.
* This is particularly relevant on Windows.
*/
return File(resourceURI.path).path.toString()
}