Skip to content

Commit

Permalink
ci: Revert oay changes to fix CI (#4463)
Browse files Browse the repository at this point in the history
* Revert "fix(integrations/webdav): Fix read file API changes (#4462)"

This reverts commit f6b4acc.

* Revert "fix(oay): support `WebdavFile` continuous reading and writing (#4374)"

This reverts commit 95cc62e.

* ci: Revert oay changes to fix CI

Signed-off-by: Xuanwo <[email protected]>

---------

Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored Apr 10, 2024
1 parent f6b4acc commit c3a81b2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 82 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci_bin_oay.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ on:
- main
paths:
- "bin/oay/**"
- "integrations/dav-server/**"
- "core/**"
- ".github/workflows/ci_bin_oay.yml"

Expand Down
52 changes: 17 additions & 35 deletions integrations/dav-server/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,70 +15,48 @@
// specific language governing permissions and limitations
// under the License.

use std::fmt;
use std::io::SeekFrom;

use bytes::{Bytes, BytesMut};
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 opendal::Reader;
use opendal::Writer;

use super::metadata::WebdavMetaData;

#[derive(Debug)]
pub struct WebdavFile {
op: Operator,
path: String,
state: WebdavFileState,
pos: u64,
}

struct WebdavFileState {
reader: Reader,
writer: Writer,
}

impl fmt::Debug for WebdavFileState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("WebdavFileState").finish()
}
path: DavPath,
}

impl WebdavFile {
pub fn new(op: Operator, reader: Reader, writer: Writer, path: String) -> Self {
Self {
op,
path,
state: WebdavFileState { reader, writer },
pos: 0,
}
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 mut buf = BytesMut::with_capacity(count);
let n = self
.state
.reader
.read(&mut buf, self.pos, count)
let file_path = self.path.as_url_string();
self.op
.read_with(&file_path)
.range(0..count as u64)
.await
.map_err(convert_error)?;
self.pos += n as u64;
Ok(buf.split().freeze())
.map(Bytes::from)
.map_err(convert_error)
}
.boxed()
}

fn metadata(&mut self) -> FsFuture<Box<dyn DavMetaData>> {
async move {
self.op
.stat(&self.path)
.stat(self.path.as_url_string().as_str())
.await
.map(|opendal_metadata| {
Box::new(WebdavMetaData::new(opendal_metadata)) as Box<dyn DavMetaData>
Expand All @@ -93,7 +71,11 @@ impl DavFile for WebdavFile {
}

fn write_bytes(&mut self, buf: Bytes) -> FsFuture<()> {
async move { self.state.writer.write(buf).await.map_err(convert_error) }.boxed()
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> {
Expand Down
5 changes: 1 addition & 4 deletions integrations/dav-server/src/opendalfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ impl DavFileSystem for OpendalFs {
_options: dav_server::fs::OpenOptions,
) -> dav_server::fs::FsFuture<Box<dyn dav_server::fs::DavFile>> {
async move {
let path = path.as_url_string();
let reader = self.op.reader(&path).await.map_err(convert_error)?;
let writer = self.op.writer(&path).await.map_err(convert_error)?;
let file = WebdavFile::new(self.op.clone(), reader, writer, path.clone());
let file = WebdavFile::new(self.op.clone(), path.clone());
Ok(Box::new(file) as Box<dyn DavFile>)
}
.boxed()
Expand Down
45 changes: 2 additions & 43 deletions integrations/dav-server/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
// under the License.

use anyhow::Result;
use bytes::Bytes;
use dav_server::davpath::DavPath;
use dav_server::fs::DavFileSystem;
use dav_server_opendalfs::OpendalFs;
use opendal::services::Fs;
use opendal::Operator;

#[tokio::test]
async fn test_metadata() -> Result<()> {
async fn test() -> Result<()> {
let mut builder = Fs::default();
builder.root("/tmp");

Expand All @@ -36,47 +35,7 @@ async fn test_metadata() -> Result<()> {
.metadata(&DavPath::new("/").unwrap())
.await
.unwrap();
assert!(metadata.is_dir());
println!("{}", metadata.is_dir());

Ok(())
}

#[tokio::test]
async fn test_write_and_read() -> Result<()> {
let mut builder = Fs::default();
builder.root("/tmp");

let op = Operator::new(builder)?.finish();

let webdavfs = OpendalFs::new(op);

let path = &DavPath::new("/test_opendalfs_write_read.txt").expect("path must be valid");
let content = "Hello dav-server-opendalfs.";

let mut davfile = webdavfs
.open(path, dav_server::fs::OpenOptions::default())
.await
.expect("open file must succeed");

let num = 999;
for i in 0..num {
davfile
.write_bytes(Bytes::from(format!("{}{}", content, i)))
.await
.expect("write file must succeed");
}

for i in 0..num {
let read_content = davfile
.read_bytes(content.len() + i.to_string().len())
.await
.expect("read file must succeed");
assert_eq!(read_content, Bytes::from(format!("{}{}", content, i)));
}

webdavfs
.remove_file(path)
.await
.expect("remove file must succeed");
Ok(())
}

0 comments on commit c3a81b2

Please sign in to comment.