Skip to content
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

feat(oay): add write for oay webdav #2769

Merged
merged 5 commits into from Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 23 additions & 8 deletions bin/oay/src/services/webdav/webdav_file.rs
Expand Up @@ -17,6 +17,7 @@

use std::io::SeekFrom;

use bytes::Bytes;
use dav_server::davpath::DavPath;
use dav_server::fs::DavFile;
use dav_server::fs::DavMetaData;
Expand All @@ -35,7 +36,7 @@ pub struct WebdavFile {
}

impl DavFile for WebdavFile {
fn read_bytes(&mut self, count: usize) -> FsFuture<bytes::Bytes> {
fn read_bytes(&mut self, count: usize) -> FsFuture<Bytes> {
async move {
let file_path = self.path.as_url_string();
let content = self
Expand All @@ -44,7 +45,7 @@ impl DavFile for WebdavFile {
.await
.unwrap();
//error handle ?
Ok(bytes::Bytes::from(content))
Ok(Bytes::from(content))
}
.boxed()
}
Expand All @@ -61,19 +62,33 @@ impl DavFile for WebdavFile {
.boxed()
}

fn write_buf(&mut self, _buf: Box<dyn bytes::Buf + Send>) -> FsFuture<()> {
todo!()
fn write_buf(&mut self, buf: Box<dyn bytes::Buf + Send>) -> FsFuture<()> {
self.write_bytes(Bytes::copy_from_slice(buf.chunk()))
}

fn write_bytes(&mut self, _buf: bytes::Bytes) -> FsFuture<()> {
todo!()
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()
}

fn seek(&mut self, _pos: SeekFrom) -> FsFuture<u64> {
todo!()
futures_util::future::err(dav_server::fs::FsError::NotImplemented).boxed()
}

fn flush(&mut self) -> FsFuture<()> {
todo!()
futures_util::future::ok(()).boxed()
}
}

fn convert_error(opendal_error: opendal::Error) -> dav_server::fs::FsError {
match opendal_error.kind() {
opendal::ErrorKind::AlreadyExists | opendal::ErrorKind::IsSameFile => {
dav_server::fs::FsError::Exists
}
opendal::ErrorKind::NotFound => dav_server::fs::FsError::NotFound,
_ => dav_server::fs::FsError::GeneralFailure,
}
}