Struct wasi_common::fs::Dir
source · pub struct Dir<'ctx> { /* private fields */ }
Expand description
A reference to an open directory on the filesystem.
TODO: Implement Dir
-using versions of std::fs
’s free functions:
copy
, create_dir
, create_dir_all
, hard_link
, metadata
,
read_link
, read_to_string
, remove_dir
, remove_dir_all
,
remove_file
, rename
, set_permissions
, symlink_metadata
, and
write
.
Unlike std::fs
, this API has no canonicalize
, because absolute paths
don’t interoperate well with the capability-oriented security model.
Implementations§
source§impl<'ctx> Dir<'ctx>
impl<'ctx> Dir<'ctx>
sourcepub unsafe fn from_raw_wasi_fd(ctx: &'ctx mut WasiCtx, fd: u32) -> Self
pub unsafe fn from_raw_wasi_fd(ctx: &'ctx mut WasiCtx, fd: u32) -> Self
Constructs a new instance of Self
from the given raw WASI file descriptor.
sourcepub fn open_file<P: AsRef<Path>>(&mut self, path: P) -> Result<File<'_>>
pub fn open_file<P: AsRef<Path>>(&mut self, path: P) -> Result<File<'_>>
Attempts to open a file in read-only mode.
This corresponds to std::fs::File::open
, but only accesses paths
relative to and within self
.
TODO: Not yet implemented. Refactor the hostcalls functions to split out the encoding/decoding parts from the underlying functionality, so that we can call into the underlying functionality directly.
sourcepub fn open_file_with<P: AsRef<Path>>(
&mut self,
path: P,
options: &OpenOptions,
) -> Result<File<'_>>
pub fn open_file_with<P: AsRef<Path>>( &mut self, path: P, options: &OpenOptions, ) -> Result<File<'_>>
Opens a file at path
with the options specified by self
.
This corresponds to std::fs::OpenOptions::open
.
Instead of being a method on OpenOptions
, this is a method on Dir
,
and it only accesses functions relative to and within self
.
TODO: Not yet implemented.
sourcepub fn open_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<Self>
pub fn open_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<Self>
Attempts to open a directory.
TODO: Not yet implemented. See the comment in open_file
.
sourcepub fn create_file<P: AsRef<Path>>(&mut self, path: P) -> Result<File<'_>>
pub fn create_file<P: AsRef<Path>>(&mut self, path: P) -> Result<File<'_>>
Opens a file in write-only mode.
This corresponds to std::fs::File::create
, but only accesses paths
relative to and within self
.
TODO: Not yet implemented. See the comment in open_file
.
sourcepub fn read(&mut self) -> Result<ReadDir>
pub fn read(&mut self) -> Result<ReadDir>
Returns an iterator over the entries within a directory.
This corresponds to std::fs::read_dir
, but reads the directory
represented by self
.
TODO: Not yet implemented. We may need to wait until we have the ability
to duplicate file descriptors before we can implement read safely. For
now, use into_read
instead.
sourcepub fn into_read(self) -> ReadDir ⓘ
pub fn into_read(self) -> ReadDir ⓘ
Consumes self and returns an iterator over the entries within a directory
in the manner of read
.