From 0f2e2406e8db003c9a6f19cd0df2d318bc083b2c Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Tue, 24 Sep 2019 17:57:06 -0700 Subject: [PATCH] imfs: Correctly mark children_enumerated when calling get_children --- src/imfs/imfs.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/imfs/imfs.rs b/src/imfs/imfs.rs index 21aaf9d4..875906c6 100644 --- a/src/imfs/imfs.rs +++ b/src/imfs/imfs.rs @@ -221,13 +221,14 @@ impl Imfs { self.read_if_not_exists(path)?; - match self.inner.get(path).unwrap() { + match self.inner.get_mut(path).unwrap() { ImfsItem::Directory(dir) => { self.fetcher.watch(path); - if dir.children_enumerated { - return self - .inner + let enumerated = dir.children_enumerated; + + if enumerated { + self.inner .children(path) .unwrap() // TODO: Handle None here, which means the PathMap entry did not exist. .into_iter() @@ -235,15 +236,17 @@ impl Imfs { .collect::>() // Collect all PathBufs, since self.get needs to borrow self mutably. .into_iter() .map(|path| self.get(path)) - .collect::>>(); - } + .collect::>>() + } else { + dir.children_enumerated = true; - self.fetcher - .read_children(path) - .map_err(|err| FsError::new(err, path.to_path_buf()))? - .into_iter() - .map(|path| self.get(path)) - .collect::>>() + self.fetcher + .read_children(path) + .map_err(|err| FsError::new(err, path.to_path_buf()))? + .into_iter() + .map(|path| self.get(path)) + .collect::>>() + } } ImfsItem::File(_) => Err(FsError::new( io::Error::new(io::ErrorKind::Other, "Can't read a directory"),