opendal icon indicating copy to clipboard operation
opendal copied to clipboard

webdav-server: Read and write are not handled correctly

Open Xuanwo opened this issue 2 years ago • 4 comments

          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

Xuanwo avatar Oct 07 '23 03:10 Xuanwo

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()
}

zhenglin-charlie-li avatar Feb 16 '24 18:02 zhenglin-charlie-li

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.

Xuanwo avatar Feb 17 '24 01:02 Xuanwo

To handle read/write correctly, we need:

  • Handle OpenOptions correctly to decide open reader or writer
  • Implement flush correctly to make sure writer closed

cc @G-XD, would you like to take a look again?

Xuanwo avatar Apr 10 '24 15:04 Xuanwo

To handle read/write correctly, we need:

  • Handle OpenOptions correctly to decide open reader or writer
  • Implement flush correctly to make sure writer closed

cc @G-XD, would you like to take a look again?

Sure, I'd be happy to take another look.

G-XD avatar Apr 11 '24 03:04 G-XD

Has been fixed.

Xuanwo avatar Nov 14 '24 07:11 Xuanwo