multithreaded scan

This commit is contained in:
🪞👃🪞 2025-03-11 15:24:15 +02:00
parent 928d38bfaa
commit a0f1577744
2 changed files with 76 additions and 37 deletions

View file

@ -57,34 +57,18 @@ pub enum EntryInfo {
}
impl Taggart {
pub fn new (root: &impl AsRef<Path>) -> Usually<Self> {
pub fn new (root: &impl AsRef<Path>, paths: Vec<Entry>) -> Usually<Self> {
Ok(Self {
_root: root.as_ref().into(),
paths: Self::collect(root)?,
cursor: 0,
offset: 0,
column: 0,
size: Measure::new(),
editing: None,
columns: Columns::default(),
paths,
})
}
pub fn collect (root: &impl AsRef<Path>) -> Usually<Vec<Entry>> {
let mut paths = vec![];
for entry in WalkDir::new(&root).into_iter()
.filter_entry(|e|!e.file_name().to_str().map(|s|s.starts_with(".")).unwrap_or(false))
{
let entry = entry?;
if entry.depth() == 0 {
continue
}
if let Some(entry) = Entry::new(root, &entry)? {
paths.push(entry);
}
}
paths.sort();
Ok(paths)
}
pub fn edit_begin (&mut self) {
let value = (self.columns.0[self.column].value)(&self.paths[self.cursor]);
let value = format!("{}", value.unwrap_or_default());
@ -110,20 +94,20 @@ impl Taggart {
}
impl Entry {
pub fn new (root: &impl AsRef<Path>, entry: &DirEntry) -> Perhaps<Self> {
println!("{}", entry.path().display());
if entry.path().is_dir() {
Self::new_dir(root, entry)
} else if entry.path().is_file() {
Self::new_file(root, entry)
pub fn new (root: &impl AsRef<Path>, path: &impl AsRef<Path>, depth: usize) -> Perhaps<Self> {
let path = path.as_ref();
if path.is_dir() {
Self::new_dir(root, &path, depth)
} else if path.is_file() {
Self::new_file(root, &path, depth)
} else {
Ok(None)
}
}
fn new_dir (root: &impl AsRef<Path>, entry: &DirEntry) -> Perhaps<Self> {
fn new_dir (root: &impl AsRef<Path>, path: &Path, depth: usize) -> Perhaps<Self> {
Ok(Some(Self {
depth: entry.depth(),
path: entry.path().strip_prefix(root.as_ref())?.into(),
depth,
path: path.into(),
info: EntryInfo::Directory {
hash_file: None,
catalog_file: None,
@ -132,11 +116,11 @@ impl Entry {
},
}))
}
fn new_file (root: &impl AsRef<Path>, entry: &DirEntry) -> Perhaps<Self> {
fn new_file (root: &impl AsRef<Path>, path: &Path, depth: usize) -> Perhaps<Self> {
Ok(Some(Self {
depth: entry.depth(),
path: entry.path().strip_prefix(root.as_ref())?.into(),
info: EntryInfo::new(&read(entry.path())?)?
depth,
path: path.into(),
info: EntryInfo::new(&read(path)?)?
}))
}
pub fn is_dir (&self) -> bool {