webdav-server: Read and write are not handled correctly
I think there is a bug where every time `write_bytes` is called, it starts writing the file from the beginning. We can fix this once we have set up `dav-server-opendalfs`.
For example: https://github.com/messense/dav-server-rs/blob/1346f52007aab7c701288b4c3e99b5e4d44369c3/src/localfs.rs#L673-L681
Originally posted by @Xuanwo in https://github.com/apache/incubator-opendal/pull/3119#discussion_r1333057389
I am interested in this issue.
Is it something like changing the https://github.com/apache/opendal/blob/main/integrations/dav-server/src/file.rs
from:
fn write_bytes(&mut self, buf: Bytes) -> FsFuture<()> {
async move {
let file_path = self.path.as_url_string();
self.op.write(&file_path, buf).await.map_err(convert_error)
}
.boxed()
}
to:
fn write_bytes(&mut self, buf: Bytes) -> FsFuture<()> {
async move {
let file_path = self.path.as_url_string();
// Open the file in append mode if supported
let write_mode = if self.op.supports_append() {
FileWriteMode::Append
} else {
FileWriteMode::Create // Use create mode as a fallback
};
self.op.write_with_mode(&file_path, buf, write_mode).await.map_err(convert_error)
}
.boxed()
}
Is it something like changing the
main/integrations/dav-server/src/file.rs
No, I believe this change requires us to store a state in WebdavFile that includes both Reader and Writer, allowing us to continue reading and writing seamlessly.
To handle read/write correctly, we need:
- Handle
OpenOptionscorrectly to decide open reader or writer - Implement
flushcorrectly to make sure writer closed
cc @G-XD, would you like to take a look again?
To handle read/write correctly, we need:
- Handle
OpenOptionscorrectly to decide open reader or writer- Implement
flushcorrectly to make sure writer closedcc @G-XD, would you like to take a look again?
Sure, I'd be happy to take another look.
Has been fixed.