@@ -200,20 +200,32 @@ impl<'a, IO: ReadWriteSeek, TP: TimeProvider, OCC: OemCpConverter> Dir<'a, IO, T
200200 ///
201201 /// `path` is a '/' separated directory path relative to self directory.
202202 ///
203+ /// An empty path returns the current directory.
204+ /// A trailing slash is ignored.
205+ /// (But the path '/' will not be found.)
206+ ///
203207 /// # Errors
204208 ///
205209 /// Errors that can be returned:
206210 ///
207211 /// * `Error::NotFound` will be returned if `path` does not point to any existing directory entry.
208212 /// * `Error::InvalidInput` will be returned if `path` points to a file that is not a directory.
209213 /// * `Error::Io` will be returned if the underlying storage object returned an I/O error.
210- pub fn open_dir ( & self , path : & str ) -> Result < Self , Error < IO :: Error > > {
214+ pub fn open_dir ( & self , mut path : & str ) -> Result < Self , Error < IO :: Error > > {
211215 trace ! ( "Dir::open_dir {}" , path) ;
212- let ( name, rest_opt) = split_path ( path) ;
213- let e = self . find_entry ( name, Some ( true ) , None ) ?;
214- match rest_opt {
215- Some ( rest) => e. to_dir ( ) . open_dir ( rest) ,
216- None => Ok ( e. to_dir ( ) ) ,
216+ let mut dir = self . clone ( ) ;
217+ loop {
218+ if path. is_empty ( ) {
219+ return Ok ( dir) ;
220+ }
221+ let ( name, rest_opt) = split_path ( path) ;
222+ dir = dir. find_entry ( name, Some ( true ) , None ) ?. to_dir ( ) ;
223+ match rest_opt {
224+ Some ( rest) => {
225+ path = rest;
226+ }
227+ None => return Ok ( dir) ,
228+ }
217229 }
218230 }
219231
0 commit comments