ls now collects metadata in a separate thread.

This commit is contained in:
cosineblast 2024-12-18 22:42:43 -03:00
parent e26364f885
commit c79ff99e0d

View File

@ -317,6 +317,7 @@ fn ls_for_one_pattern(
};
let hidden_dir_specified = is_hidden_dir(pattern_arg.as_ref());
let path = pattern_arg.into_spanned(p_tag);
let (prefix, paths) = if just_read_dir {
let expanded = nu_path::expand_path_with(path.item.as_ref(), &cwd, path.item.is_expand());
@ -359,7 +360,8 @@ fn ls_for_one_pattern(
};
pool.install(|| {
paths_peek
rayon::spawn(move || {
let result = paths_peek
.par_bridge()
.filter_map(move |x| match x {
Ok(path) => {
@ -391,8 +393,9 @@ fn ls_for_one_pattern(
if let Ok(remainder) = path.strip_prefix(prefix) {
if directory {
// When the path is the same as the cwd, path_diff should be "."
let path_diff =
if let Some(path_diff_not_dot) = diff_paths(&path, &cwd) {
let path_diff = if let Some(path_diff_not_dot) =
diff_paths(&path, &cwd)
{
let path_diff_not_dot = path_diff_not_dot.to_string_lossy();
if path_diff_not_dot.is_empty() {
".".to_string()
@ -459,14 +462,19 @@ fn ls_for_one_pattern(
inner: vec![],
})
})
})
.map_err(|err| ShellError::GenericError {
error: "Unable to create a rayon pool".into(),
msg: err.to_string(),
span: Some(call_span),
help: None,
inner: vec![],
})?;
});
if let Err(error) = result {
let _ = tx.send(Value::error(error, call_span));
}
});
});
Ok(rx
.into_iter()