|
1 | | -use super::{parse_response, vfs_request, DirEntry, VfsAction, VfsError, VfsResponse}; |
| 1 | +use super::{parse_response, vfs_request, DirEntry, FileType, VfsAction, VfsError, VfsResponse}; |
2 | 2 |
|
3 | 3 | /// Vfs helper struct for a directory. |
4 | 4 | /// Opening or creating a directory will give you a Result<Directory>. |
@@ -36,13 +36,38 @@ impl Directory { |
36 | 36 | pub fn open_dir(path: &str, create: bool, timeout: Option<u64>) -> Result<Directory, VfsError> { |
37 | 37 | let timeout = timeout.unwrap_or(5); |
38 | 38 | if !create { |
| 39 | + let message = vfs_request(path, VfsAction::Metadata) |
| 40 | + .send_and_await_response(timeout) |
| 41 | + .unwrap() |
| 42 | + .map_err(|e| VfsError::IOError { |
| 43 | + error: e.to_string(), |
| 44 | + path: path.to_string(), |
| 45 | + })?; |
| 46 | + match parse_response(message.body())? { |
| 47 | + VfsResponse::Metadata(m) => { |
| 48 | + if m.file_type != FileType::Directory { |
| 49 | + return Err(VfsError::IOError { |
| 50 | + error: "Entry at path not a directory".to_string(), |
| 51 | + path: path.to_string(), |
| 52 | + }); |
| 53 | + } |
| 54 | + } |
| 55 | + VfsResponse::Err(e) => return Err(e), |
| 56 | + _ => { |
| 57 | + return Err(VfsError::ParseError { |
| 58 | + error: "unexpected response".to_string(), |
| 59 | + path: path.to_string(), |
| 60 | + }) |
| 61 | + } |
| 62 | + } |
| 63 | + |
39 | 64 | return Ok(Directory { |
40 | 65 | path: path.to_string(), |
41 | 66 | timeout, |
42 | 67 | }); |
43 | 68 | } |
44 | 69 |
|
45 | | - let message = vfs_request(path, VfsAction::CreateDir) |
| 70 | + let message = vfs_request(path, VfsAction::CreateDirAll) |
46 | 71 | .send_and_await_response(timeout) |
47 | 72 | .unwrap() |
48 | 73 | .map_err(|e| VfsError::IOError { |
|
0 commit comments