xxfast / KStore

A tiny Kotlin multiplatform library that assists in saving and restoring objects to and from disk using kotlinx.coroutines, kotlinx.serialisation and kotlinx.io
https://xxfast.github.io/KStore/
Apache License 2.0
470 stars 15 forks source link

Versioned fileStore crashes on Android #99

Closed JanTie closed 3 months ago

JanTie commented 4 months ago

Currently (version 0.7.2 but i guess its more like since 0.7.0) the versioned KStore cannot be instantiated on Android devices. Creating such a KStore results in: java.io.FileNotFoundException: $my_store.json.version: open failed: EROFS (Read-only file system) However, using the same path "${context.filesDir.toPath().pathString}/my_store.json".toPath() in the regular storeOf function works perfectly fine.

Not sure if the leading Dollar is intended or not, but i just scrolled a bit into the changes and it seems like the 0.7.0 fix for #69 might have caused such versioned KStores to always be created on the root level of the File-System. Which in case of an Android file System will always be Read-Only. Imo the version jsons should be created in the same directory as the store itself. Tinkering with it i could even reproduce this within the KVersionedStoreTests when i use a relative path and comment out the deletion test. The store file is created at the correct location, but the version file will always be created at the root directory of the current launching scope.

xxfast commented 3 months ago

Nice catch and thanks for fixing it 👍 Your fix should be available to test out on the latest 0.8.0-SNAPSHOT