Skip to content

Commit

Permalink
refactor(dav-server): Polish dav-server integration details
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo committed Jun 17, 2024
1 parent f95248b commit d9d9bc9
Show file tree
Hide file tree
Showing 12 changed files with 416 additions and 208 deletions.
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,30 @@ OpenDAL offers a unified data access layer, empowering users to seamlessly and e

## For *ANY* integrations

| Name | Description | Release |
|------------------------|------------------------------------------------------|-------------------------------------------------------------|
| [dav-server-opendalfs] | Access data via integrations to [dav-server-rs] | [![dav-server-opendalfs image]][dav-server-opendalfs crate] |
| [object_store_opendal] | Access data via integrations to [object_store] | [![object_store_opendal image]][object_store_opendal crate] |
| [fuse3_opendal] | Access data via integrations to [fuse3] | - |
| [virtiofs_opendal] | Access data via integrations to [vhost-user-backend] | - |
| Name | Description | Release | Docs |
|------------------------|------------------------------------------------------|---------------------------------------------|-----------------------------------------------------------------------------------|
| [dav-server-opendalfs] | a [dav-server-rs] implementation using opendal. | [![dav-server image]][dav-server crate] | [![Docs Release]][dav-server release docs] [![Docs Dev]][dav-server dev docs] |
| [object_store_opendal] | an [object_store] implementation using opendal. | [![object_store image]][object_store crate] | [![Docs Release]][object_store release docs] [![Docs Dev]][object_store dev docs] |
| [fuse3_opendal] | Access data via integrations to [fuse3] | - | - |
| [virtiofs_opendal] | Access data via integrations to [vhost-user-backend] | - | - |

[dav-server-opendalfs]: integrations/dav-server/README.md
[dav-server-rs]: https://github.com/messense/dav-server-rs
[dav-server-opendalfs image]: https://img.shields.io/crates/v/dav-server-opendalfs.svg
[dav-server-opendalfs crate]: https://crates.io/crates/dav-server-opendalfs
[dav-server image]: https://img.shields.io/crates/v/dav-server-opendalfs.svg
[dav-server crate]: https://crates.io/crates/dav-server-opendalfs
[dav-server release docs]: https://docs.rs/dav-server-opendalfs/
[dav-server dev docs]: https://opendal.apache.org/docs/dav-server-opendalfs/dav_server_opendalfs/

[object_store_opendal]: integrations/object_store/README.md
[object_store]: https://docs.rs/object_store
[object_store_opendal image]: https://img.shields.io/crates/v/object_store_opendal.svg
[object_store_opendal crate]: https://crates.io/crates/object_store_opendal
[object_store image]: https://img.shields.io/crates/v/object_store_opendal.svg
[object_store crate]: https://crates.io/crates/object_store_opendal
[object_store release docs]: https://docs.rs/object_store_opendal/
[object_store dev docs]: https://opendal.apache.org/docs/object-store-opendal/object_store_opendal/

[fuse3_opendal]: integrations/fuse3/README.md
[fuse3]: https://docs.rs/fuse3

[virtiofs_opendal]: integrations/virtiofs/README.md
[vhost-user-backend]: https://docs.rs/vhost-user-backend

Expand Down
2 changes: 1 addition & 1 deletion core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ OpenDAL offers a unified data access layer, empowering users to seamlessly and e

## Useful Links

- Documentation: [stable](https://docs.rs/opendal/) | [main](https://opendal.apache.org/docs/rust/opendal/)
- Documentation: [release](https://docs.rs/opendal/) | [dev](https://opendal.apache.org/docs/rust/opendal/)
- [Release Notes](https://docs.rs/opendal/latest/opendal/docs/changelog/index.html)
- [Upgrade Guide](https://docs.rs/opendal/latest/opendal/docs/upgrade/index.html)
- [RFC List](https://docs.rs/opendal/latest/opendal/docs/rfcs/index.html)
Expand Down
13 changes: 5 additions & 8 deletions integrations/dav-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,16 @@ rust-version = "1.75"
[dependencies]
anyhow = "1"
bytes = { version = "1.4.0" }
chrono = "0.4.28"
dav-server = { version = "0.5.8" }
dirs = "5.0.0"
dav-server = { version = "0.6.0" }
futures = "0.3"
futures-util = { version = "0.3.16" }
opendal = { version = "0.47.0", path = "../../core" }

[dev-dependencies]
opendal = { version = "0.47.0", path = "../../core", features = [
"services-fs",
] }
quick-xml = { version = "0.32", features = ["serialize", "overlapped-lists"] }
serde = { version = "1", features = ["derive"] }
tokio = { version = "1.27", features = [
"fs",
"macros",
"rt-multi-thread",
"io-std",
] }
] }
58 changes: 56 additions & 2 deletions integrations/dav-server/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
# dav-server-opendalfs
# Apache OpenDAL™ dav-server integration

[`dav-server-opendalfs`](https://crates.io/crates/dav-server-opendalfs) is an integration which uses OpenDAL as a backend to access data in various service with WebDAV protocol.
[![Build Status]][actions] [![Latest Version]][crates.io] [![Crate Downloads]][crates.io] [![chat]][discord]

[build status]: https://img.shields.io/github/actions/workflow/status/apache/opendal/ci_integration_dav_server.yml?branch=main
[actions]: https://github.com/apache/opendal/actions?query=branch%3Amain
[latest version]: https://img.shields.io/crates/v/dav-server-opendalfs.svg
[crates.io]: https://crates.io/crates/dav-server-opendalfs
[crate downloads]: https://img.shields.io/crates/d/dav-server-opendalfs.svg
[chat]: https://img.shields.io/discord/1081052318650339399
[discord]: https://opendal.apache.org/discord

`dav-server-opendalfs` is an [`dav-server`](https://github.com/messense/dav-server-rs) implementation using opendal.

This crate can help you to access ANY storage services with the same webdav API.

## Useful Links

- Documentation: [release](https://docs.rs/dav-server-opendalfs/) | [dev](https://opendal.apache.org/docs/dav-server-opendalfs/dav_server_opendalfs/)

## Examples

```
use anyhow::Result;
use dav_server::davpath::DavPath;
use dav_server::fs::DavFileSystem;
use dav_server_opendalfs::OpendalFs;
use opendal::services::Memory;
use opendal::Operator;
#[tokio::test]
async fn test() -> Result<()> {
let op = Operator::new(Memory::default())?.finish();
let webdavfs = OpendalFs::new(op);
let metadata = webdavfs
.metadata(&DavPath::new("/").unwrap())
.await
.unwrap();
println!("{}", metadata.is_dir());
Ok(())
}
```

## Branding

The first and most prominent mentions must use the full form: **Apache OpenDAL™** of the name for any individual usage (webpage, handout, slides, etc.) Depending on the context and writing style, you should use the full form of the name sufficiently often to ensure that readers clearly understand the association of both the OpenDAL project and the OpenDAL software product to the ASF as the parent organization.

For more details, see the [Apache Product Name Usage Guide](https://www.apache.org/foundation/marks/guide).

## License and Trademarks

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

Apache OpenDAL, OpenDAL, and Apache are either registered trademarks or trademarks of the Apache Software Foundation.
86 changes: 86 additions & 0 deletions integrations/dav-server/src/dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// 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, DavMetaData};
use futures::StreamExt;
use futures::{FutureExt, Stream};
use opendal::Operator;
use opendal::{Entry, Lister};
use std::pin::Pin;
use std::task::Poll::Ready;
use std::task::{ready, Context, Poll};

use super::metadata::OpendalMetaData;
use super::utils::*;

/// OpendalStream is a stream of `DavDirEntry` that is used to list the contents of a directory.
pub struct OpendalStream {
op: Operator,
lister: Lister,
}

impl OpendalStream {
/// Create a new opendal stream.
pub fn new(op: Operator, lister: Lister) -> Self {
OpendalStream { op, lister }
}
}

impl Stream for OpendalStream {
type Item = Box<dyn DavDirEntry>;

fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let dav_stream = self.get_mut();
match ready!(dav_stream.lister.poll_next_unpin(cx)) {
Some(entry) => {
let webdav_entry = OpendalDirEntry::new(dav_stream.op.clone(), entry.unwrap());
Ready(Some(Box::new(webdav_entry) as Box<dyn DavDirEntry>))
}
None => Ready(None),
}
}
}

/// OpendalDirEntry is a `DavDirEntry` implementation for opendal.
pub struct OpendalDirEntry {
op: Operator,
dir_entry: Entry,
}

impl OpendalDirEntry {
/// Create a new opendal dir entry.
pub fn new(op: Operator, dir_entry: Entry) -> Self {
OpendalDirEntry { dir_entry, op }
}
}

impl DavDirEntry for OpendalDirEntry {
fn name(&self) -> Vec<u8> {
self.dir_entry.name().as_bytes().to_vec()
}

fn metadata(&self) -> dav_server::fs::FsFuture<Box<dyn DavMetaData>> {
async move {
self.op
.stat(self.dir_entry.path())
.await
.map(|metadata| Box::new(OpendalMetaData::new(metadata)) as Box<dyn DavMetaData>)
.map_err(convert_error)
}
.boxed()
}
}
54 changes: 0 additions & 54 deletions integrations/dav-server/src/dir_entry.rs

This file was deleted.

Loading

0 comments on commit d9d9bc9

Please sign in to comment.