Closed SultanArshad closed 1 month ago
I might be wrong, but after a bit of investigation, I think the issue is with the FileCodec declaration. The parent directory for the file seems to be missing from the following declaration:
public inline fun <reified T : @Serializable Any> FileCodec(
file: Path,
tempFile: Path = Path("${file.name}.temp"),
json: Json = DefaultJson,
): FileCodec<T> = FileCodec(
file = file,
tempFile = tempFile,
json = json,
serializer = json.serializersModule.serializer(),
)
Probable Solutions:
public inline fun <reified T : @Serializable Any> FileCodec(
file: Path,
tempFile: Path = Path("${file.parent}/${file.name}.temp"),
json: Json = DefaultJson,
): FileCodec<T> = FileCodec(
file = file,
tempFile = tempFile,
json = json,
serializer = json.serializersModule.serializer(),
)
Nice catch guys!
I think we should be able to do just
public inline fun <reified T : @Serializable Any> FileCodec(
file: Path,
tempFile: Path = Path("$file.temp"),
json: Json = DefaultJson,
): FileCodec<T> = FileCodec(
file = file,
tempFile = tempFile,
json = json,
serializer = json.serializersModule.serializer(),
)
PRs welcome :)
Done! Released on 0.9.0
. Thank you for the contribution
App crashes on start-up after using 0.9.0-SNAPSHOT.
What I have done so far/How to reproduce:
Removed okio from the project.
Using import kotlinx.io.files.Path instead. e.g
val fileDir: String = get<DirectoryProvider>().fileDir
file = Path("$fileDir/$FILE_NAME_HERE.json")
.I installed a fresh app with a clean build and invalidated the cache.
Logs:
FATAL EXCEPTION: DefaultDispatcher-worker-1 Process: packageName, PID: 7697 java.io.FileNotFoundException: File does not exist: fileName.json.temp at kotlinx.io.files.FileSystemJvmKt$SystemFileSystem$1.delete(FileSystemJvm.kt:61) at kotlinx.io.files.FileSystem.delete$default(FileSystem.kt:50) at io.github.xxfast.kstore.file.FileCodec.encode(FileCodec.kt:68) at io.github.xxfast.kstore.KStore$write$2.invokeSuspend(KStore.kt:56) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101) at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:113) at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:589) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:823) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:720) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:707) Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@e0ff0d, Dispatchers.Default]