-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FileHandle from SeekableByteChannel #3299
FileHandle from SeekableByteChannel #3299
Conversation
Instead of no-opping or erroring those methods, maybe we need to extract a parent interface? I.e. if all you have is a |
Yes that would probably be a better solution but requires greater changes. What about a |
I guess that's my other question. Do you actually need a |
Well actually I just want to use readAll and writeAll. If WriteCursor and ReadCursor were a trait they could be implemented using SeekableByteChannel. Then I could catch the UnsupportedOperationException in Files.readCursor and Files.writeCursor and use the SeekableByteChannel implementation instead. Since that is not easily changable and ReadCursor and WriteCursor require a FileHandle I could construct the hacky FileHandle just for the cursors but it would still be accessible to the library user. |
Thanks for the exposition. Hmm, that's frustrating. It seems that |
I thought a bit about this but this currently seems to be the only way to get it working. I now made the unsupported methods throw an UnsupportedOperationException so instead of getting one when you open the FileHandle without this PR you now get one when using the unsupported methods which is probably equally unsafe. So its still somewhat of an hack but it gets reading and writing working with unsupported filesystems. |
Throwing for the unsupported operations seems fine to me. Couple thoughts:
I think the |
The implementation actually tries to set the position on non-sequential writes and will throw if the SeekableByteChannel doesn't support this doesn't it? This is a mutable operation though unlike in the FileChannel impl. |
Whoops, you are right. I misread the guard. Objection withdrawn.On Oct 3, 2023, at 8:40 AM, Pierre Kisters ***@***.***> wrote:
Throwing for the unsupported operations seems fine to me. Couple thoughts:
If position is not settable, we can't even implement write correctly. The implementation of write in this PR is only safe for sequential writes.
We should consider re-raising the original open error upon failure to open a byte channel.
I think the write issue is enough of a reason to not provide a WriteCursor for non-seekable channels.
The implementation actually tries to set the position on non-sequential writes and will throw if the SeekableByteChannel doesn't support this doesn't it? This is a mutable operation though unlike in the FileChannel impl.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
|
I changed the PR to re-raise the original exception that is thrown when creating the FileChannel. Is the mima error a real problem? As far as I can tell the hierarchy is sealed enough that it shouldn't cause any problems or am I missing something? |
This one seems okay to filter, unfortunately MiMa doesn't recognized |
81ac53b
to
a727bf4
Compare
I have added the mima exclusion, a test and updated the branch. The PR should now be ready to review. |
Thanks! |
Hi! I wanted to use https://github.com/robtimus/sftp-fs with the fs2 Files api. It turns out that some file systems don't implement a FileChannel so in this PR I propose a fallback solution to use SeekableByteChannel if necessary.
The FileHandle will not support features like locking in that case. Currently these methods just return F[Unit] but it might be better for them to throw an UnsupportedOperationException. Feedback would be welcome!