@@ -18,12 +18,12 @@ use std::{io, path::Path};
1818/// don't interoperate well with the capability-oriented security model.
1919pub struct Dir < ' ctx > {
2020 ctx : & ' ctx WasiCtx ,
21- fd : types:: Fd ,
21+ fd : & ' ctx types:: Fd ,
2222}
2323
2424impl < ' ctx > Dir < ' ctx > {
2525 /// Constructs a new instance of `Self` from the given raw WASI file descriptor.
26- pub unsafe fn from_raw_wasi_fd ( ctx : & ' ctx WasiCtx , fd : types:: Fd ) -> Self {
26+ pub unsafe fn from_raw_wasi_fd ( ctx : & ' ctx WasiCtx , fd : & ' ctx types:: Fd ) -> Self {
2727 Self { ctx, fd }
2828 }
2929
@@ -38,9 +38,6 @@ impl<'ctx> Dir<'ctx> {
3838 ///
3939 /// [`std::fs::File::open`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.open
4040 pub fn open_file < P : AsRef < Path > > ( & mut self , path : P ) -> io:: Result < File > {
41- let path = path. as_ref ( ) ;
42- let mut fd = types:: Fd :: from ( 0 ) ;
43-
4441 // TODO: Refactor the hostcalls functions to split out the encoding/decoding
4542 // parts from the underlying functionality, so that we can call into the
4643 // underlying functionality directly.
@@ -51,6 +48,9 @@ impl<'ctx> Dir<'ctx> {
5148 // on `OsStrExt`.
5249 unimplemented ! ( "Dir::open_file" ) ;
5350 /*
51+ let path = path.as_ref();
52+ let mut fd = types::Fd { raw: types::RawFd::from(0) };
53+
5454 wasi_errno_to_io_error(hostcalls::path_open(
5555 self.ctx,
5656 self.fd,
@@ -63,10 +63,10 @@ impl<'ctx> Dir<'ctx> {
6363 0,
6464 &mut fd,
6565 ))?;
66- */
6766
6867 let ctx = self.ctx;
6968 Ok(unsafe { File::from_raw_wasi_fd(ctx, fd) })
69+ */
7070 }
7171
7272 /// Opens a file at `path` with the options specified by `self`.
@@ -91,12 +91,12 @@ impl<'ctx> Dir<'ctx> {
9191 ///
9292 /// TODO: Not yet implemented. See the comment in `open_file`.
9393 pub fn open_dir < P : AsRef < Path > > ( & mut self , path : P ) -> io:: Result < Self > {
94- let path = path. as_ref ( ) ;
95- let mut fd = types:: Fd :: from ( 0 ) ;
96-
9794 // TODO: See the comment in `open_file`.
9895 unimplemented ! ( "Dir::open_dir" ) ;
9996 /*
97+ let path = path.as_ref();
98+ let mut fd = types::Fd { raw: types::RawFd::from(0) };
99+
100100 wasi_errno_to_io_error(hostcalls::path_open(
101101 self.ctx,
102102 self.fd,
@@ -108,10 +108,10 @@ impl<'ctx> Dir<'ctx> {
108108 0,
109109 &mut fd,
110110 ))?;
111- */
112111
113112 let ctx = self.ctx;
114113 Ok(unsafe { Dir::from_raw_wasi_fd(ctx, fd) })
114+ */
115115 }
116116
117117 /// Opens a file in write-only mode.
@@ -123,14 +123,14 @@ impl<'ctx> Dir<'ctx> {
123123 ///
124124 /// [`std::fs::File::create`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.create
125125 pub fn create_file < P : AsRef < Path > > ( & mut self , path : P ) -> io:: Result < File > {
126- let path = path. as_ref ( ) ;
127- let mut fd = types:: Fd :: from ( 0 ) ;
128-
129126 // TODO: See the comments in `open_file`.
130127 //
131128 // TODO: Set the requested rights to be read+write.
132129 unimplemented ! ( "Dir::create_file" ) ;
133130 /*
131+ let path = path.as_ref();
132+ let mut fd = types::Fd { raw: types::RawFd::from(0) };
133+
134134 wasi_errno_to_io_error(hostcalls::path_open(
135135 self.ctx,
136136 self.fd,
@@ -143,10 +143,10 @@ impl<'ctx> Dir<'ctx> {
143143 0,
144144 &mut fd,
145145 ))?;
146- */
147146
148147 let ctx = self.ctx;
149148 Ok(unsafe { File::from_raw_wasi_fd(ctx, fd) })
149+ */
150150 }
151151
152152 /// Returns an iterator over the entries within a directory.
@@ -159,13 +159,13 @@ impl<'ctx> Dir<'ctx> {
159159 /// now, use `into_read` instead.
160160 ///
161161 /// [`std::fs::read_dir`]: https://doc.rust-lang.org/std/fs/fn.read_dir.html
162- pub fn read ( & mut self ) -> io:: Result < ReadDir > {
162+ pub fn read ( & mut self ) -> io:: Result < ReadDir < ' ctx > > {
163163 unimplemented ! ( "Dir::read" )
164164 }
165165
166166 /// Consumes self and returns an iterator over the entries within a directory
167167 /// in the manner of `read`.
168- pub fn into_read ( self ) -> ReadDir {
168+ pub fn into_read ( self ) -> ReadDir < ' ctx > {
169169 unsafe { ReadDir :: from_raw_wasi_fd ( self . fd ) }
170170 }
171171
@@ -189,7 +189,7 @@ impl<'ctx> Dir<'ctx> {
189189 /// relative to and within `self`.
190190 ///
191191 /// [`std::fs::read_dir`]: https://doc.rust-lang.org/std/fs/fn.read_dir.html
192- pub fn read_dir < P : AsRef < Path > > ( & mut self , path : P ) -> io:: Result < ReadDir > {
192+ pub fn read_dir < P : AsRef < Path > > ( & mut self , path : P ) -> io:: Result < ReadDir < ' ctx > > {
193193 self . open_dir ( path) ?. read ( )
194194 }
195195}
0 commit comments