Skip to content

Commit fc06c3b

Browse files
[JVM Windows] Process shutdown bug (#162)
1 parent cb270b3 commit fc06c3b

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
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-BETA29 (unreleased)
44

55
* Fix potential race condition between jobs in `connect()` and `disconnect()`.
6+
* [JVM Windows] Fixed PowerSync Extension temporary file deletion error on process shutdown.
67
* [iOS] Fixed issue where automatic driver migrations would fail with the error:
78
```
89
Sqlite operation failure database is locked attempted to run migration and failed. closing connection

core/src/jvmMain/kotlin/com/powersync/DatabaseDriverFactory.jvm.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ public actual class DatabaseDriverFactory {
5757
}
5858

5959
public companion object {
60-
private val powersyncExtension: String = extractLib("powersync").toString()
60+
private val powersyncExtension: String = extractLib("powersync")
6161
}
6262
}
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package com.powersync
22

3-
import java.nio.file.Path
4-
import kotlin.io.path.createTempFile
5-
import kotlin.io.path.deleteIfExists
6-
import kotlin.io.path.outputStream
3+
import java.io.File
74

85
private class R
96

10-
internal fun extractLib(fileName: String): Path {
7+
internal fun extractLib(fileName: String): String {
118
val os = System.getProperty("os.name").lowercase()
129
val (prefix, extension) =
1310
when {
@@ -26,14 +23,12 @@ internal fun extractLib(fileName: String): Path {
2623

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

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

32-
(R::class.java.getResourceAsStream(path) ?: error("Resource $path not found")).use { input ->
33-
tmpPath.outputStream().use { output ->
34-
input.copyTo(output)
35-
}
36-
}
37-
38-
return tmpPath
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()
3934
}

0 commit comments

Comments
 (0)