style: fix clippy

This commit is contained in:
andy.boot
2025-10-06 20:18:12 +01:00
parent 04b80b474c
commit d00519085a
3 changed files with 57 additions and 55 deletions
+3 -3
View File
@@ -269,15 +269,15 @@ pub fn get_config(conf_path: Option<&String>) -> Config {
None => { None => {
if let Some(home) = directories::BaseDirs::new() { if let Some(home) = directories::BaseDirs::new() {
for path in get_config_locations(home.home_dir()) { for path in get_config_locations(home.home_dir()) {
if path.exists() { if path.exists()
if let Ok(config) = Config::from_config_file(&path) { && let Ok(config) = Config::from_config_file(&path)
{
return config; return config;
} }
} }
} }
} }
} }
}
Config { Config {
..Default::default() ..Default::default()
} }
+13 -17
View File
@@ -69,13 +69,12 @@ pub fn walk_it(dirs: HashSet<PathBuf>, walk_data: &WalkData) -> Vec<Node> {
// Remove files which have the same inode, we don't want to double count them. // Remove files which have the same inode, we don't want to double count them.
fn clean_inodes(x: Node, inodes: &mut HashSet<(u64, u64)>, walk_data: &WalkData) -> Option<Node> { fn clean_inodes(x: Node, inodes: &mut HashSet<(u64, u64)>, walk_data: &WalkData) -> Option<Node> {
if !walk_data.use_apparent_size { if !walk_data.use_apparent_size
if let Some(id) = x.inode_device { && let Some(id) = x.inode_device
if !inodes.insert(id) { && !inodes.insert(id)
{
return None; return None;
} }
}
}
// Sort Nodes so iteration order is predictable // Sort Nodes so iteration order is predictable
let mut tmp: Vec<_> = x.children; let mut tmp: Vec<_> = x.children;
@@ -156,19 +155,19 @@ fn ignore_file(entry: &DirEntry, walk_data: &WalkData) -> bool {
if !walk_data.allowed_filesystems.is_empty() { if !walk_data.allowed_filesystems.is_empty() {
let size_inode_device = get_metadata(entry.path(), false, follow_links); let size_inode_device = get_metadata(entry.path(), false, follow_links);
if let Some((_size, Some((_id, dev)), _gunk)) = size_inode_device { if let Some((_size, Some((_id, dev)), _gunk)) = size_inode_device
if !walk_data.allowed_filesystems.contains(&dev) { && !walk_data.allowed_filesystems.contains(&dev)
{
return true; return true;
} }
} }
}
if walk_data.filter_accessed_time.is_some() if walk_data.filter_accessed_time.is_some()
|| walk_data.filter_modified_time.is_some() || walk_data.filter_modified_time.is_some()
|| walk_data.filter_changed_time.is_some() || walk_data.filter_changed_time.is_some()
{ {
let size_inode_device = get_metadata(entry.path(), false, follow_links); let size_inode_device = get_metadata(entry.path(), false, follow_links);
if let Some((_, _, (modified_time, accessed_time, changed_time))) = size_inode_device { if let Some((_, _, (modified_time, accessed_time, changed_time))) = size_inode_device
if entry.path().is_file() && entry.path().is_file()
&& [ && [
(&walk_data.filter_modified_time, modified_time), (&walk_data.filter_modified_time, modified_time),
(&walk_data.filter_accessed_time, accessed_time), (&walk_data.filter_accessed_time, accessed_time),
@@ -182,7 +181,6 @@ fn ignore_file(entry: &DirEntry, walk_data: &WalkData) -> bool {
return true; return true;
} }
} }
}
// Keeping `walk_data.filter_regex.is_empty()` is important for performance reasons, it stops unnecessary work // Keeping `walk_data.filter_regex.is_empty()` is important for performance reasons, it stops unnecessary work
if !walk_data.filter_regex.is_empty() if !walk_data.filter_regex.is_empty()
@@ -222,8 +220,9 @@ fn walk(dir: PathBuf, walk_data: &WalkData, depth: usize) -> Option<Node> {
// return walk(entry.path(), walk_data, depth) // return walk(entry.path(), walk_data, depth)
if !ignore_file(entry, walk_data) { if !ignore_file(entry, walk_data)
if let Ok(data) = entry.file_type() { && let Ok(data) = entry.file_type()
{
if data.is_dir() if data.is_dir()
|| (walk_data.follow_links && data.is_symlink()) || (walk_data.follow_links && data.is_symlink())
{ {
@@ -241,15 +240,12 @@ fn walk(dir: PathBuf, walk_data: &WalkData, depth: usize) -> Option<Node> {
prog_data.num_files.fetch_add(1, ORDERING); prog_data.num_files.fetch_add(1, ORDERING);
if let Some(ref file) = node { if let Some(ref file) = node {
prog_data prog_data.total_file_size.fetch_add(file.size, ORDERING);
.total_file_size
.fetch_add(file.size, ORDERING);
} }
return node; return node;
} }
} }
}
Err(ref failed) => { Err(ref failed) => {
if handle_error_and_retry(failed, &dir, walk_data) { if handle_error_and_retry(failed, &dir, walk_data) {
return walk(dir.clone(), walk_data, depth); return walk(dir.clone(), walk_data, depth);
+8 -2
View File
@@ -106,14 +106,20 @@ pub fn test_ignore_all_in_file() {
#[test] #[test]
pub fn test_files_from_flag_file() { pub fn test_files_from_flag_file() {
let output = build_command(vec!["--files-from", "tests/test_dir_files_from/files_from.txt"]); let output = build_command(vec![
"--files-from",
"tests/test_dir_files_from/files_from.txt",
]);
assert!(output.contains("a_file")); assert!(output.contains("a_file"));
assert!(output.contains("hello_file")); assert!(output.contains("hello_file"));
} }
#[test] #[test]
pub fn test_files0_from_flag_file() { pub fn test_files0_from_flag_file() {
let output = build_command(vec!["--files0-from", "tests/test_dir_files_from/files0_from.txt"]); let output = build_command(vec![
"--files0-from",
"tests/test_dir_files_from/files0_from.txt",
]);
assert!(output.contains("a_file")); assert!(output.contains("a_file"));
assert!(output.contains("hello_file")); assert!(output.contains("hello_file"));
} }