Skip to content

Commit

Permalink
Always return ReadDirResutls, no longer an option
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegrosjean committed Feb 5, 2019
1 parent 5b4745e commit 32d6b86
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
16 changes: 5 additions & 11 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn walk<P, S, F, E>(path: P, state: S, f: F) -> OrderedQueueIter<ReadDirResu
where
P: Into<PathBuf>,
S: Send + Clone + 'static,
F: Fn(ReadDirSpec<S>) -> Option<ReadDirResult<S, E>> + Send + Clone + 'static,
F: Fn(ReadDirSpec<S>) -> ReadDirResult<S, E> + Send + Clone + 'static,
E: Send + 'static,
{
let path = path.into();
Expand Down Expand Up @@ -69,7 +69,7 @@ fn walk_dir<F, S, E>(
ordered_read_dir_spec: Ordered<ReadDirSpec<S>>,
run_context: &mut RunContext<S, E>,
) where
F: Fn(ReadDirSpec<S>) -> Option<ReadDirResult<S, E>> + Send + Clone + 'static,
F: Fn(ReadDirSpec<S>) -> ReadDirResult<S, E> + Send + Clone + 'static,
S: Send + Clone + 'static,
E: Send,
{
Expand All @@ -80,13 +80,7 @@ fn walk_dir<F, S, E>(
} = ordered_read_dir_spec;

// 1. Get read_dir_result from f
let read_dir_result: ReadDirResult<S, E> = match f(read_dir_spec) {
Some(read_dir_result) => read_dir_result,
_ => {
run_context.stop();
return;
}
};
let read_dir_result = f(read_dir_spec);

// 2. Generate ordered_children_specs from read_dir_result
let children_specs: Option<Vec<_>> = read_dir_result.as_ref().ok().map(|dir_entries| {
Expand Down Expand Up @@ -233,7 +227,7 @@ mod tests {
let mut dir_entry_results = Vec::new();
let read_dir_spec_iter = match fs::read_dir(&read_dir_spec.path) {
Ok(read_dir_spec_iter) => read_dir_spec_iter,
Err(err) => return Some(Err(err)),
Err(err) => return Err(err),
};

for each in read_dir_spec_iter {
Expand All @@ -250,7 +244,7 @@ mod tests {
children_spec,
}));
}
Some(Ok(dir_entry_results))
Ok(dir_entry_results)
})
.collect();
assert!(dir_entry_lists.len() == 3);
Expand Down
7 changes: 4 additions & 3 deletions src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl IntoIterator for WalkDir {
let dir_entry_list_iter = core::walk(&self.root, Ignore {}, move |read_dir_spec| {
let read_dir_iter = match fs::read_dir(&read_dir_spec.path) {
Ok(read_dir_iter) => read_dir_iter,
Err(err) => return Some(Err(err)),
Err(err) => return Err(err),
};

let mut dir_entries: Vec<_> = read_dir_iter
Expand All @@ -78,8 +78,8 @@ impl IntoIterator for WalkDir {
};

let file_type = dir_entry.file_type();

let metadata = LazyCell::new();

if preload_metadata {
metadata.fill(dir_entry.metadata()).unwrap();
}
Expand Down Expand Up @@ -109,14 +109,15 @@ impl IntoIterator for WalkDir {
})
.collect();

// Sort hardcoded right now
dir_entries.sort_by(|a, b| match (a, b) {
(Ok(a), Ok(b)) => a.value.file_name.cmp(&b.value.file_name),
(Ok(_), Err(_)) => Ordering::Less,
(Err(_), Ok(_)) => Ordering::Greater,
(Err(_), Err(_)) => Ordering::Equal,
});

Some(Ok(dir_entries))
Ok(dir_entries)
});

let mut iter = WalkDirIter {
Expand Down

0 comments on commit 32d6b86

Please sign in to comment.