From 815e340f855612cbc005f160fb39a767f3531285 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 20 Mar 2020 16:33:19 -0700 Subject: [PATCH] Add an `is_directory()` helper method. (#1373) This allows `ctx` to avoid depending on wasi::FileType. --- crates/wasi-common/src/ctx.rs | 2 +- crates/wasi-common/src/virtfs.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/wasi-common/src/ctx.rs b/crates/wasi-common/src/ctx.rs index f3b38ed2e2..d7e5ae5fca 100644 --- a/crates/wasi-common/src/ctx.rs +++ b/crates/wasi-common/src/ctx.rs @@ -351,7 +351,7 @@ impl WasiCtxBuilder { } } Descriptor::VirtualFile(virt) => { - if virt.get_file_type() != types::Filetype::Directory { + if !virt.is_directory() { return Err(WasiCtxBuilderError::NotADirectory(guest_path)); } } diff --git a/crates/wasi-common/src/virtfs.rs b/crates/wasi-common/src/virtfs.rs index c955c1663d..f6247aa805 100644 --- a/crates/wasi-common/src/virtfs.rs +++ b/crates/wasi-common/src/virtfs.rs @@ -137,6 +137,10 @@ pub(crate) trait VirtualFile: MovableFile { fn get_file_type(&self) -> types::Filetype; + fn is_directory(&self) -> bool { + self.get_file_type() == types::Filetype::Directory + } + fn get_rights_base(&self) -> types::Rights { types::Rights::empty() }