diff --git a/Cargo.lock b/Cargo.lock index 67c44c3..5c4a106 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1448,7 +1448,7 @@ dependencies = [ [[package]] name = "kinode_process_lib" -version = "0.9.0" +version = "0.9.1" dependencies = [ "alloy", "alloy-primitives", diff --git a/Cargo.toml b/Cargo.toml index 485e750..a34b4ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kinode_process_lib" description = "A library for writing Kinode processes in Rust." -version = "0.9.0" +version = "0.9.1" edition = "2021" license-file = "LICENSE" homepage = "https://kinode.org" diff --git a/src/vfs/directory.rs b/src/vfs/directory.rs index 55ecdc7..2fc07cf 100644 --- a/src/vfs/directory.rs +++ b/src/vfs/directory.rs @@ -1,4 +1,4 @@ -use super::{parse_response, vfs_request, DirEntry, VfsAction, VfsError, VfsResponse}; +use super::{parse_response, vfs_request, DirEntry, FileType, VfsAction, VfsError, VfsResponse}; /// Vfs helper struct for a directory. /// Opening or creating a directory will give you a Result. @@ -36,13 +36,38 @@ impl Directory { pub fn open_dir(path: &str, create: bool, timeout: Option) -> Result { let timeout = timeout.unwrap_or(5); if !create { + let message = vfs_request(path, VfsAction::Metadata) + .send_and_await_response(timeout) + .unwrap() + .map_err(|e| VfsError::IOError { + error: e.to_string(), + path: path.to_string(), + })?; + match parse_response(message.body())? { + VfsResponse::Metadata(m) => { + if m.file_type != FileType::Directory { + return Err(VfsError::IOError { + error: "Entry at path not a directory".to_string(), + path: path.to_string(), + }); + } + } + VfsResponse::Err(e) => return Err(e), + _ => { + return Err(VfsError::ParseError { + error: "unexpected response".to_string(), + path: path.to_string(), + }) + } + } + return Ok(Directory { path: path.to_string(), timeout, }); } - let message = vfs_request(path, VfsAction::CreateDir) + let message = vfs_request(path, VfsAction::CreateDirAll) .send_and_await_response(timeout) .unwrap() .map_err(|e| VfsError::IOError {