Skip to content

Commit 0e1aacc

Browse files
committed
vfs: fix directory async
1 parent 4beff93 commit 0e1aacc

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/vfs/directory/directory_async.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{parse_response, vfs_request, DirEntry, FileType, VfsAction, VfsError, VfsResponse};
1+
use super::{vfs_request, DirEntry, FileType, VfsAction, VfsError, VfsResponse};
22
use crate::hyperapp;
33

44
pub struct DirectoryAsync {
@@ -10,16 +10,16 @@ impl DirectoryAsync {
1010
pub async fn read(&self) -> Result<Vec<DirEntry>, VfsError> {
1111
let request = vfs_request(&self.path, VfsAction::ReadDir).expects_response(self.timeout);
1212

13-
let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
13+
let response = hyperapp::send::<VfsResponse>(request)
1414
.await
1515
.map_err(|_| VfsError::SendError(crate::SendErrorKind::Timeout))?;
1616

17-
match parse_response(&resp_bytes)? {
17+
match response {
1818
VfsResponse::ReadDir(entries) => Ok(entries),
1919
VfsResponse::Err(e) => Err(e),
2020
_ => Err(VfsError::ParseError {
2121
error: "unexpected response".to_string(),
22-
path: self.path.clone(),
22+
path: self.path.to_string(),
2323
}),
2424
}
2525
}
@@ -34,11 +34,11 @@ pub async fn open_dir_async(
3434
if !create {
3535
let request = vfs_request(path, VfsAction::Metadata).expects_response(timeout);
3636

37-
let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
37+
let response = hyperapp::send::<VfsResponse>(request)
3838
.await
3939
.map_err(|_| VfsError::SendError(crate::SendErrorKind::Timeout))?;
4040

41-
match parse_response(&resp_bytes)? {
41+
match response {
4242
VfsResponse::Metadata(m) => {
4343
if m.file_type != FileType::Directory {
4444
return Err(VfsError::IOError(
@@ -47,12 +47,10 @@ pub async fn open_dir_async(
4747
}
4848
}
4949
VfsResponse::Err(e) => return Err(e),
50-
_ => {
51-
return Err(VfsError::ParseError {
52-
error: "unexpected response".to_string(),
53-
path: path.to_string(),
54-
})
55-
}
50+
_ => return Err(VfsError::ParseError {
51+
error: "unexpected response".to_string(),
52+
path: path.to_string(),
53+
}),
5654
}
5755

5856
return Ok(DirectoryAsync {
@@ -63,11 +61,11 @@ pub async fn open_dir_async(
6361

6462
let request = vfs_request(path, VfsAction::CreateDirAll).expects_response(timeout);
6563

66-
let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
64+
let response = hyperapp::send::<VfsResponse>(request)
6765
.await
6866
.map_err(|_| VfsError::SendError(crate::SendErrorKind::Timeout))?;
6967

70-
match parse_response(&resp_bytes)? {
68+
match response {
7169
VfsResponse::Ok => Ok(DirectoryAsync {
7270
path: path.to_string(),
7371
timeout,
@@ -85,11 +83,11 @@ pub async fn remove_dir_async(path: &str, timeout: Option<u64>) -> Result<(), Vf
8583

8684
let request = vfs_request(path, VfsAction::RemoveDir).expects_response(timeout);
8785

88-
let resp_bytes = hyperapp::send_rmp::<Vec<u8>>(request)
86+
let response = hyperapp::send::<VfsResponse>(request)
8987
.await
9088
.map_err(|_| VfsError::SendError(crate::SendErrorKind::Timeout))?;
9189

92-
match parse_response(&resp_bytes)? {
90+
match response {
9391
VfsResponse::Ok => Ok(()),
9492
VfsResponse::Err(e) => Err(e),
9593
_ => Err(VfsError::ParseError {

0 commit comments

Comments
 (0)