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

fix(oay): add some error handle #2879

Merged
merged 3 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions bin/oay/src/services/webdav/webdav_dir_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
// under the License.

use dav_server::fs::DavDirEntry;
use dav_server::fs::DavMetaData;
use futures::FutureExt;
use opendal::Entry;
use opendal::Operator;

use super::webdav_file::convert_error;
use super::webdav_metadata::WebdavMetaData;

pub struct WebDAVDirEntry {
Expand All @@ -35,8 +35,13 @@ impl DavDirEntry for WebDAVDirEntry {

fn metadata(&self) -> dav_server::fs::FsFuture<Box<dyn dav_server::fs::DavMetaData>> {
async move {
let metedata = self.op.stat(self.dir_entry.path()).await.unwrap();
Ok(Box::new(WebdavMetaData::new(metedata)) as Box<dyn DavMetaData>)
self.op
.stat(self.dir_entry.path())
.await
.map(|metadata| {
Box::new(WebdavMetaData::new(metadata)) as Box<dyn dav_server::fs::DavMetaData>
})
.map_err(convert_error)
}
.boxed()
}
Expand Down
19 changes: 10 additions & 9 deletions bin/oay/src/services/webdav/webdav_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,26 @@ impl DavFile for WebdavFile {
fn read_bytes(&mut self, count: usize) -> FsFuture<Bytes> {
async move {
let file_path = self.path.as_url_string();
let content = self
.op
self.op
.range_read(&file_path, 0..count as u64)
.await
.unwrap();
//error handle ?
Ok(Bytes::from(content))
.map(Bytes::from)
.map_err(convert_error)
}
.boxed()
}

fn metadata(&mut self) -> FsFuture<Box<dyn DavMetaData>> {
async move {
let opendal_metadata = self
.op
self.op
.stat(self.path.as_url_string().as_str())
.await
.unwrap();
Ok(Box::new(WebdavMetaData::new(opendal_metadata)) as Box<dyn DavMetaData>)
.map_or_else(
Xuanwo marked this conversation as resolved.
Show resolved Hide resolved
|e| Err(convert_error(e)),
|opendal_metadata| {
Ok(Box::new(WebdavMetaData::new(opendal_metadata)) as Box<dyn DavMetaData>)
},
)
}
.boxed()
}
Expand Down
9 changes: 7 additions & 2 deletions bin/oay/src/services/webdav/webdavfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ impl DavFileSystem for WebdavFs {
) -> dav_server::fs::FsFuture<dav_server::fs::FsStream<Box<dyn dav_server::fs::DavDirEntry>>>
{
async move {
let lister = self.op.lister(path.as_url_string().as_str()).await.unwrap();
Ok(DavStream::new(self.op.clone(), lister).boxed())
self.op
.lister(path.as_url_string().as_str())
.await
.map_or_else(
Xuanwo marked this conversation as resolved.
Show resolved Hide resolved
|e| Err(convert_error(e)),
|lister| Ok(DavStream::new(self.op.clone(), lister).boxed()),
)
}
.boxed()
}
Expand Down