-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oay): port
WebdavFs
to dav-server-fs-opendal (#3119)
- Loading branch information
1 parent
d535d62
commit 3176d21
Showing
12 changed files
with
558 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ members = [ | |
"bin/oay", | ||
|
||
"integrations/object_store", | ||
"integrations/dav-server", | ||
] | ||
resolver = "2" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
[package] | ||
description = "Use OpenDAL as a backend to access data in various service with WebDAV protocol" | ||
name = "dav-server-opendalfs" | ||
|
||
authors.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
version.workspace = true | ||
|
||
[dependencies] | ||
anyhow = "1" | ||
chrono = "0.4.28" | ||
dirs = "5.0.0" | ||
bytes = { version = "1.4.0" } | ||
dav-server = { version = "0.5.5" } | ||
futures = "0.3" | ||
futures-util = { version = "0.3.16" } | ||
opendal.workspace = true | ||
quick-xml = { version = "0.29", features = ["serialize", "overlapped-lists"] } | ||
serde = { version = "1", features = ["derive"] } | ||
tokio = { version = "1.27", features = [ | ||
"fs", | ||
"macros", | ||
"rt-multi-thread", | ||
"io-std", | ||
] } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# dav-server-opendalfs | ||
|
||
`dav-server-opendalfs` is a integration which use OpenDAL as a backend to access data in various service with WebDAV protocol. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use dav_server::fs::DavDirEntry; | ||
use futures::FutureExt; | ||
use opendal::Entry; | ||
use opendal::Operator; | ||
|
||
use super::file::convert_error; | ||
use super::metadata::WebdavMetaData; | ||
|
||
pub struct WebDAVDirEntry { | ||
dir_entry: Entry, | ||
op: Operator, | ||
} | ||
|
||
impl DavDirEntry for WebDAVDirEntry { | ||
fn name(&self) -> Vec<u8> { | ||
self.dir_entry.name().as_bytes().to_vec() | ||
} | ||
|
||
fn metadata(&self) -> dav_server::fs::FsFuture<Box<dyn dav_server::fs::DavMetaData>> { | ||
async move { | ||
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() | ||
} | ||
} | ||
|
||
impl WebDAVDirEntry { | ||
pub fn new(dir_entry: Entry, op: Operator) -> Self { | ||
WebDAVDirEntry { dir_entry, op } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use std::io::SeekFrom; | ||
|
||
use bytes::Bytes; | ||
use dav_server::davpath::DavPath; | ||
use dav_server::fs::DavFile; | ||
use dav_server::fs::DavMetaData; | ||
use dav_server::fs::FsFuture; | ||
use futures::FutureExt; | ||
use opendal::Operator; | ||
|
||
use super::metadata::WebdavMetaData; | ||
|
||
#[derive(Debug)] | ||
pub struct WebdavFile { | ||
op: Operator, | ||
path: DavPath, | ||
} | ||
|
||
impl WebdavFile { | ||
pub fn new(op: Operator, path: DavPath) -> Self { | ||
Self { op, path } | ||
} | ||
} | ||
|
||
impl DavFile for WebdavFile { | ||
fn read_bytes(&mut self, count: usize) -> FsFuture<Bytes> { | ||
async move { | ||
let file_path = self.path.as_url_string(); | ||
self.op | ||
.read_with(&file_path) | ||
.range(0..count as u64) | ||
.await | ||
.map(Bytes::from) | ||
.map_err(convert_error) | ||
} | ||
.boxed() | ||
} | ||
|
||
fn metadata(&mut self) -> FsFuture<Box<dyn DavMetaData>> { | ||
async move { | ||
self.op | ||
.stat(self.path.as_url_string().as_str()) | ||
.await | ||
.map(|opendal_metadata| { | ||
Box::new(WebdavMetaData::new(opendal_metadata)) as Box<dyn DavMetaData> | ||
}) | ||
.map_err(convert_error) | ||
} | ||
.boxed() | ||
} | ||
|
||
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) -> 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> { | ||
futures_util::future::err(dav_server::fs::FsError::NotImplemented).boxed() | ||
} | ||
|
||
fn flush(&mut self) -> FsFuture<()> { | ||
futures_util::future::ok(()).boxed() | ||
} | ||
} | ||
|
||
pub 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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
mod dir_entry; | ||
mod file; | ||
mod metadata; | ||
mod opendalfs; | ||
|
||
pub use opendalfs::OpendalFs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use dav_server::fs::DavMetaData; | ||
use dav_server::fs::FsError; | ||
use opendal::Metadata; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct WebdavMetaData { | ||
metadata: Metadata, | ||
} | ||
|
||
impl WebdavMetaData { | ||
pub fn new(metadata: Metadata) -> Self { | ||
WebdavMetaData { metadata } | ||
} | ||
} | ||
|
||
impl DavMetaData for WebdavMetaData { | ||
fn len(&self) -> u64 { | ||
self.metadata.content_length() | ||
} | ||
|
||
fn modified(&self) -> dav_server::fs::FsResult<std::time::SystemTime> { | ||
match self.metadata.last_modified() { | ||
Some(t) => Ok(t.into()), | ||
None => Err(FsError::GeneralFailure), | ||
} | ||
} | ||
|
||
fn is_dir(&self) -> bool { | ||
self.metadata.is_dir() | ||
} | ||
|
||
fn is_file(&self) -> bool { | ||
self.metadata.is_file() | ||
} | ||
|
||
fn etag(&self) -> Option<String> { | ||
self.metadata.etag().map(|s| s.to_string()) | ||
} | ||
|
||
fn status_changed(&self) -> dav_server::fs::FsResult<std::time::SystemTime> { | ||
self.metadata | ||
.last_modified() | ||
.map_or(Err(FsError::GeneralFailure), |t| Ok(t.into())) | ||
} | ||
} |
Oops, something went wrong.