From 04cb5f085474584be5ffc7f40137fa0f11586728 Mon Sep 17 00:00:00 2001 From: Suyan Date: Wed, 12 Jul 2023 23:09:32 +0800 Subject: [PATCH] feat(services/webdav): impl sink (#2622) --- core/src/services/webdav/backend.rs | 6 +++++- core/src/services/webdav/writer.rs | 24 +++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/core/src/services/webdav/backend.rs b/core/src/services/webdav/backend.rs index fbc323c82b1..825e2f067ae 100644 --- a/core/src/services/webdav/backend.rs +++ b/core/src/services/webdav/backend.rs @@ -277,9 +277,13 @@ impl Accessor for WebdavBackend { read_with_range: true, write: true, + write_can_sink: true, + create_dir: true, delete: true, + copy: true, + rename: true, list: true, @@ -471,7 +475,7 @@ impl WebdavBackend { pub async fn webdav_put( &self, abs_path: &str, - size: Option, + size: Option, content_type: Option<&str>, content_disposition: Option<&str>, body: AsyncBody, diff --git a/core/src/services/webdav/writer.rs b/core/src/services/webdav/writer.rs index 5ccccba5794..a3c17bafa7d 100644 --- a/core/src/services/webdav/writer.rs +++ b/core/src/services/webdav/writer.rs @@ -35,19 +35,16 @@ impl WebdavWriter { pub fn new(backend: WebdavBackend, op: OpWrite, path: String) -> Self { WebdavWriter { backend, op, path } } -} -#[async_trait] -impl oio::Write for WebdavWriter { - async fn write(&mut self, bs: Bytes) -> Result<()> { + async fn write_oneshot(&mut self, size: u64, body: AsyncBody) -> Result<()> { let resp = self .backend .webdav_put( &self.path, - Some(bs.len()), + Some(size), self.op.content_type(), self.op.content_disposition(), - AsyncBody::Bytes(bs), + body, ) .await?; @@ -61,12 +58,17 @@ impl oio::Write for WebdavWriter { _ => Err(parse_error(resp).await?), } } +} + +#[async_trait] +impl oio::Write for WebdavWriter { + async fn write(&mut self, bs: Bytes) -> Result<()> { + self.write_oneshot(bs.len() as u64, AsyncBody::Bytes(bs)) + .await + } - async fn sink(&mut self, _size: u64, _s: oio::Streamer) -> Result<()> { - Err(Error::new( - ErrorKind::Unsupported, - "Write::sink is not supported", - )) + async fn sink(&mut self, size: u64, s: oio::Streamer) -> Result<()> { + self.write_oneshot(size, AsyncBody::Stream(s)).await } async fn abort(&mut self) -> Result<()> {