Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
brmmm3 committed Oct 25, 2024
1 parent fbb82c6 commit ad2c604
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 29 deletions.
6 changes: 5 additions & 1 deletion scandir/src/scandir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,11 @@ impl Scandir {
}

pub fn collect(&mut self) -> Result<ScandirResults, Error> {
println!("collect: finished={}", self.finished());
println!(
"collect: finished={} duration={}",
self.finished(),
self.duration()
);
if !self.finished() {
println!("collect: busy={}", self.busy());
if !self.busy() {
Expand Down
71 changes: 43 additions & 28 deletions scandir/src/walk.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use std::fmt::Debug;
use std::fs::{ self, Metadata };
use std::io::{ Error, ErrorKind };
use std::fs::{self, Metadata};
use std::io::{Error, ErrorKind};
use std::path::Path;
use std::sync::atomic::{ AtomicBool, Ordering };
use std::sync::{ Arc, Mutex };
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Instant;

use flume::{ unbounded, Receiver, Sender };
use flume::{unbounded, Receiver, Sender};
use jwalk_meta::WalkDirGeneric;
use speedy::Writable;

use crate::common::{ check_and_expand_path, create_filter, filter_children, get_root_path_len };
use crate::common::{check_and_expand_path, create_filter, filter_children, get_root_path_len};
use crate::def::*;

#[inline]
fn update_toc(
dir_entry: &jwalk_meta::DirEntry<((), Option<Result<fs::Metadata, Error>>)>,
toc: &mut Toc
toc: &mut Toc,
) {
let file_type = dir_entry.file_type;
let key = dir_entry.file_name.clone().into_string().unwrap();
Expand All @@ -36,14 +36,19 @@ pub fn toc_thread(
options: Options,
filter: Option<Filter>,
tx: Sender<(String, Toc)>,
stop: Arc<AtomicBool>
stop: Arc<AtomicBool>,
) {
let root_path_len = get_root_path_len(&options.root_path);

let dir_entry: jwalk_meta::DirEntry<
((), Option<Result<Metadata, Error>>)
> = jwalk_meta::DirEntry
::from_path(0, &options.root_path, true, true, false, Arc::new(Vec::new()))
let dir_entry: jwalk_meta::DirEntry<((), Option<Result<Metadata, Error>>)> =
jwalk_meta::DirEntry::from_path(
0,
&options.root_path,
true,
true,
false,
Arc::new(Vec::new()),
)
.unwrap();

if !dir_entry.file_type.is_dir() {
Expand Down Expand Up @@ -86,7 +91,8 @@ pub fn toc_thread(
let _ = tx.send(("".to_owned(), toc));
}
}
}) {
})
{
if stop.load(Ordering::Relaxed) {
break;
}
Expand Down Expand Up @@ -251,13 +257,11 @@ impl Walk {
self.stop.store(false, Ordering::Relaxed);
let stop = self.stop.clone();
let duration = self.duration.clone();
self.thr = Some(
thread::spawn(move || {
let start_time = Instant::now();
toc_thread(options, filter, tx, stop);
*duration.lock().unwrap() = start_time.elapsed().as_secs_f64();
})
);
self.thr = Some(thread::spawn(move || {
let start_time = Instant::now();
toc_thread(options, filter, tx, stop);
*duration.lock().unwrap() = start_time.elapsed().as_secs_f64();
}));
Ok(())
}

Expand Down Expand Up @@ -296,7 +300,13 @@ impl Walk {
}

pub fn collect(&mut self) -> Result<Toc, Error> {
println!(
"collect: finished={} duration={}",
self.finished(),
self.duration()
);
if !self.finished() {
println!("collect: busy={}", self.busy());
if !self.busy() {
self.start()?;
}
Expand All @@ -323,7 +333,11 @@ impl Walk {

pub fn results_cnt(&mut self, only_new: bool) -> usize {
if let Some(ref rx) = self.rx {
if only_new { rx.len() } else { self.entries.len() + rx.len() }
if only_new {
rx.len()
} else {
self.entries.len() + rx.len()
}
} else {
self.entries.len()
}
Expand All @@ -345,21 +359,18 @@ impl Walk {
}

pub fn errors_cnt(&mut self) -> usize {
self.entries
.iter()
.map(|e| e.1.errors.len())
.sum()
self.entries.iter().map(|e| e.1.errors.len()).sum()
}

pub fn errors(&mut self, only_new: bool) -> ErrorsType {
self.results(only_new)
.iter()
.flat_map(|e|
.flat_map(|e| {
e.1.errors
.iter()
.map(|err| (e.0.clone(), err.to_string()))
.collect::<Vec<_>>()
)
})
.collect::<Vec<_>>()
}

Expand Down Expand Up @@ -399,7 +410,11 @@ impl Walk {
}

pub fn busy(&self) -> bool {
if let Some(ref thr) = self.thr { !thr.is_finished() } else { false }
if let Some(ref thr) = self.thr {
!thr.is_finished()
} else {
false
}
}

// For debugging
Expand Down

0 comments on commit ad2c604

Please sign in to comment.