korlibs / korlibs/korlibs-io

No APPEND mode for opening file on Android

Open
#21 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
2
Forks
2
PR merge metrics
No merged PRs in 30d

Description

I have this code in Kotlin Multiplatform Mobile project:
```kotlin
dstFile.vfs.open(dstFile.path, VfsOpenMode.APPEND).use {
setPosition(rangeData?.startIndex ?: 0)
writeBytes(bytes)
}
```
and I get this error on Android:
```
java.lang.UnsupportedOperationException: APPEND not allowed
at sun.nio.fs.UnixChannelFactory.newAsynchronousFileChannel(UnixChannelFactory.java:172)
at sun.nio.fs.UnixFileSystemProvider.newAsynchronousFileChannel(UnixFileSystemProvider.java:200)
at java.nio.channels.AsynchronousFileChannel.open(AsynchronousFileChannel.java:253)
at java.nio.channels.AsynchronousFileChannel.open(AsynchronousFileChannel.java:311)
at korlibs.io.file.std.AsynchronousFileChannelVfs$openAsynchronousFileChannel$2.invokeSuspend(AsynchronousFileChannelVfs.kt:60)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:124)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:820)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in AsynchronousFileChannelVfs.kt at the openAsynchronousFileChannel call shown in the stack trace, and inspect how VfsOpenMode.APPEND is passed to Android's file channel. Reproduce the failure with the Kotlin Multiplatform Mobile example, then verify that APPEND opens successfully and preserves the requested write behavior without the UnsupportedOperationException.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile-dev, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.