Skip to content

Commit

Permalink
hack
Browse files Browse the repository at this point in the history
  • Loading branch information
bootandy committed Jan 3, 2024
1 parent cd53fc7 commit 6bcbacd
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 54 deletions.
123 changes: 69 additions & 54 deletions src/dir_walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,66 +126,81 @@ fn ignore_file(entry: &DirEntry, walk_data: &WalkData) -> bool {

fn walk(dir: PathBuf, walk_data: &WalkData, depth: usize) -> Option<Node> {
let prog_data = &walk_data.progress_data;
let mut children = vec![];

if let Ok(entries) = fs::read_dir(&dir) {
children = entries
.into_iter()
.par_bridge()
.filter_map(|entry| {
if let Ok(ref entry) = entry {
// uncommenting the below line gives simpler code but
// rayon doesn't parallelize as well giving a 3X performance drop
// hence we unravel the recursion a bit

// return walk(entry.path(), walk_data, depth)

if !ignore_file(entry, walk_data) {
if let Ok(data) = entry.file_type() {
if data.is_dir() || (walk_data.follow_links && data.is_symlink()) {
return walk(entry.path(), walk_data, depth + 1);
let read_dir = fs::read_dir(&dir);
match read_dir {
Ok(entries) => {
let children = entries
.into_iter()
.par_bridge()
.filter_map(|entry| {
if let Ok(ref entry) = entry {
// uncommenting the below line gives simpler code but
// rayon doesn't parallelize as well giving a 3X performance drop
// hence we unravel the recursion a bit

// return walk(entry.path(), walk_data, depth)

if !ignore_file(entry, walk_data) {
if let Ok(data) = entry.file_type() {
if data.is_dir() || (walk_data.follow_links && data.is_symlink()) {
return walk(entry.path(), walk_data, depth + 1);
}

let node = build_node(
entry.path(),
vec![],
walk_data.filter_regex,
walk_data.invert_filter_regex,
walk_data.use_apparent_size,
data.is_symlink(),
data.is_file(),
walk_data.by_filecount,
depth,
);

prog_data.num_files.fetch_add(1, ORDERING);
if let Some(ref file) = node {
prog_data.total_file_size.fetch_add(file.size, ORDERING);
}

return node;
}

let node = build_node(
entry.path(),
vec![],
walk_data.filter_regex,
walk_data.invert_filter_regex,
walk_data.use_apparent_size,
data.is_symlink(),
data.is_file(),
walk_data.by_filecount,
depth,
);

prog_data.num_files.fetch_add(1, ORDERING);
if let Some(ref file) = node {
prog_data.total_file_size.fetch_add(file.size, ORDERING);
}

return node;
}
} else {
println!("HIT early");
prog_data.no_permissions.store(true, ORDERING)
}
} else {
None
})
.collect();
build_node(
dir,
children,
walk_data.filter_regex,
walk_data.invert_filter_regex,
walk_data.use_apparent_size,
false,
false,
walk_data.by_filecount,
depth,
)
},
Err(failed) => {
match failed.kind() {
std::io::ErrorKind::PermissionDenied => {
prog_data.no_permissions.store(true, ORDERING)
},
std::io::ErrorKind::NotFound=> {
prog_data.no_file.store(true, ORDERING)
},
_ => {
prog_data.unknown_error.store(true, ORDERING)
}
None
})
.collect();
} else if !dir.is_file() {
walk_data.progress_data.no_permissions.store(true, ORDERING)
}
return None

Check failure on line 200 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Style (ubuntu-latest)

unneeded `return` statement

Check failure on line 200 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Style (ubuntu-latest)

unneeded `return` statement

Check failure on line 200 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Style (macos-latest)

unneeded `return` statement

Check failure on line 200 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Style (macos-latest)

unneeded `return` statement

Check failure on line 200 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Style (windows-latest)

unneeded `return` statement

Check failure on line 200 in src/dir_walker.rs

View workflow job for this annotation

GitHub Actions / Style (windows-latest)

unneeded `return` statement
}
}
build_node(
dir,
children,
walk_data.filter_regex,
walk_data.invert_filter_regex,
walk_data.use_apparent_size,
false,
false,
walk_data.by_filecount,
depth,
)

}

mod tests {
Expand Down
8 changes: 8 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,19 @@ fn main() {
};

let failed_permissions = indicator.data.no_permissions.load(ORDERING);
let no_file = indicator.data.no_file.load(ORDERING);
let unknown_error = indicator.data.unknown_error.load(ORDERING);
indicator.stop();
// Must have stopped indicator before we print to stderr
if failed_permissions {
eprintln!("Did not have permissions for all directories");
}
if no_file {
eprintln!("No such file or directory");
}
if unknown_error {
eprintln!("Unknown Error reading files");
}

if let Some(root_node) = tree {
let idd = InitialDisplayData {
Expand Down
2 changes: 2 additions & 0 deletions src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub struct PAtomicInfo {
pub state: AtomicU8,
pub current_path: ThreadStringWrapper,
pub no_permissions: AtomicBool,
pub no_file: AtomicBool,
pub unknown_error: AtomicBool,
}

impl PAtomicInfo {
Expand Down

0 comments on commit 6bcbacd

Please sign in to comment.