fix: create Application Support directory before opening Room database on iOS

This commit is contained in:
Garfie 2026-04-05 15:42:34 -05:00
parent d8bdfa843b
commit 21825a4943

View file

@ -20,14 +20,21 @@ import okio.Path.Companion.toPath
import org.koin.core.module.Module
import org.koin.dsl.binds
import org.koin.dsl.module
import platform.Foundation.NSFileManager
import platform.Foundation.NSHomeDirectory
@OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
private fun ensureDirectoryExists(path: String) {
NSFileManager.defaultManager.createDirectoryAtPath(path, withIntermediateDirectories = true, attributes = null, error = null)
}
actual val dataPlatformModule: Module = module {
// --- Database ---
single {
val dbPath = NSHomeDirectory() + "/Library/Application Support/librechat.db"
Room.databaseBuilder<LibreChatDatabase>(name = dbPath)
val dbDir = NSHomeDirectory() + "/Library/Application Support"
ensureDirectoryExists(dbDir)
Room.databaseBuilder<LibreChatDatabase>(name = "$dbDir/librechat.db")
.setDriver(BundledSQLiteDriver())
.setQueryCoroutineContext(Dispatchers.IO)
.build()
@ -35,7 +42,9 @@ actual val dataPlatformModule: Module = module {
// --- DataStore ---
single<DataStore<Preferences>> {
val path = NSHomeDirectory() + "/Library/Application Support/datastore/$DATASTORE_FILE_NAME.preferences_pb"
val datastoreDir = NSHomeDirectory() + "/Library/Application Support/datastore"
ensureDirectoryExists(datastoreDir)
val path = "$datastoreDir/$DATASTORE_FILE_NAME.preferences_pb"
PreferenceDataStoreFactory.createWithPath(
produceFile = { path.toPath() },
)