mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Obey new clippy
Clippy is like having a reviewer fix your dodgy code.
This commit is contained in:
+23
-12
@@ -12,7 +12,7 @@ pub fn draw_it(
|
|||||||
depth: Option<u64>,
|
depth: Option<u64>,
|
||||||
base_dirs: HashSet<String>,
|
base_dirs: HashSet<String>,
|
||||||
to_display: Vec<(String, u64)>,
|
to_display: Vec<(String, u64)>,
|
||||||
) -> () {
|
) {
|
||||||
if !permissions {
|
if !permissions {
|
||||||
eprintln!("Did not have permissions for all directories");
|
eprintln!("Did not have permissions for all directories");
|
||||||
}
|
}
|
||||||
@@ -20,12 +20,20 @@ pub fn draw_it(
|
|||||||
|
|
||||||
for &(ref k, _) in to_display.iter() {
|
for &(ref k, _) in to_display.iter() {
|
||||||
if base_dirs.contains(k) {
|
if base_dirs.contains(k) {
|
||||||
display_node(&k, &mut found, &to_display, true, short_paths, depth, "─┬");
|
display_node(
|
||||||
|
&k,
|
||||||
|
&mut found,
|
||||||
|
&to_display,
|
||||||
|
true,
|
||||||
|
short_paths,
|
||||||
|
depth,
|
||||||
|
"─┬",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_size(nodes: &Vec<(String, u64)>, node_to_print: &String) -> Option<u64> {
|
fn get_size(nodes: &[(String, u64)], node_to_print: &str) -> Option<u64> {
|
||||||
for &(ref k, ref v) in nodes.iter() {
|
for &(ref k, ref v) in nodes.iter() {
|
||||||
if *k == *node_to_print {
|
if *k == *node_to_print {
|
||||||
return Some(*v);
|
return Some(*v);
|
||||||
@@ -35,9 +43,9 @@ fn get_size(nodes: &Vec<(String, u64)>, node_to_print: &String) -> Option<u64> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn display_node<S: Into<String>>(
|
fn display_node<S: Into<String>>(
|
||||||
node_to_print: &String,
|
node_to_print: &str,
|
||||||
found: &mut HashSet<String>,
|
found: &mut HashSet<String>,
|
||||||
to_display: &Vec<(String, u64)>,
|
to_display: &[(String, u64)],
|
||||||
is_biggest: bool,
|
is_biggest: bool,
|
||||||
short_paths: bool,
|
short_paths: bool,
|
||||||
depth: Option<u64>,
|
depth: Option<u64>,
|
||||||
@@ -56,7 +64,7 @@ fn display_node<S: Into<String>>(
|
|||||||
match get_size(to_display, node_to_print) {
|
match get_size(to_display, node_to_print) {
|
||||||
None => println!("Can not find path: {}", node_to_print),
|
None => println!("Can not find path: {}", node_to_print),
|
||||||
Some(size) => {
|
Some(size) => {
|
||||||
let ntp: &str = node_to_print.as_ref();
|
let ntp: &str = node_to_print;
|
||||||
let num_slashes = node_to_print.matches('/').count();
|
let num_slashes = node_to_print.matches('/').count();
|
||||||
|
|
||||||
let is = indentation_str.into();
|
let is = indentation_str.into();
|
||||||
@@ -96,7 +104,7 @@ fn clean_indentation_string<S: Into<String>>(s: S) -> String {
|
|||||||
is
|
is
|
||||||
}
|
}
|
||||||
|
|
||||||
fn count_siblings(to_display: &Vec<(String, u64)>, num_slashes: usize, ntp: &str) -> u64 {
|
fn count_siblings(to_display: &[(String, u64)], num_slashes: usize, ntp: &str) -> u64 {
|
||||||
to_display.iter().fold(0, |a, b| {
|
to_display.iter().fold(0, |a, b| {
|
||||||
if b.0.starts_with(ntp) && b.0.matches('/').count() == num_slashes + 1 {
|
if b.0.starts_with(ntp) && b.0.matches('/').count() == num_slashes + 1 {
|
||||||
a + 1
|
a + 1
|
||||||
@@ -106,7 +114,12 @@ fn count_siblings(to_display: &Vec<(String, u64)>, num_slashes: usize, ntp: &str
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_children(to_display: &Vec<(String, u64)>, new_depth: Option<u64>, ntp: &str, num_slashes: usize) -> bool {
|
fn has_children(
|
||||||
|
to_display: &[(String, u64)],
|
||||||
|
new_depth: Option<u64>,
|
||||||
|
ntp: &str,
|
||||||
|
num_slashes: usize,
|
||||||
|
) -> bool {
|
||||||
if new_depth.is_none() || new_depth.unwrap() != 1 {
|
if new_depth.is_none() || new_depth.unwrap() != 1 {
|
||||||
for &(ref k2, _) in to_display.iter() {
|
for &(ref k2, _) in to_display.iter() {
|
||||||
if k2.starts_with(ntp) && k2.matches('/').count() == num_slashes + 1 {
|
if k2.starts_with(ntp) && k2.matches('/').count() == num_slashes + 1 {
|
||||||
@@ -114,7 +127,7 @@ fn has_children(to_display: &Vec<(String, u64)>, new_depth: Option<u64>, ntp: &s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_tree_chars(has_smaller_siblings: bool, has_children: bool) -> &'static str {
|
fn get_tree_chars(has_smaller_siblings: bool, has_children: bool) -> &'static str {
|
||||||
@@ -124,14 +137,12 @@ fn get_tree_chars(has_smaller_siblings: bool, has_children: bool) -> &'static st
|
|||||||
} else {
|
} else {
|
||||||
"└──"
|
"└──"
|
||||||
}
|
}
|
||||||
} else {
|
} else if has_children {
|
||||||
if has_children {
|
|
||||||
"├─┬"
|
"├─┬"
|
||||||
} else {
|
} else {
|
||||||
"├──"
|
"├──"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn print_this_node(
|
fn print_this_node(
|
||||||
node_name: &str,
|
node_name: &str,
|
||||||
|
|||||||
+7
-1
@@ -91,7 +91,13 @@ fn main() {
|
|||||||
Some(d) => trim_deep_ones(sorted_data, d, &simplified_dirs),
|
Some(d) => trim_deep_ones(sorted_data, d, &simplified_dirs),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
draw_it(permissions, !use_full_path, depth, simplified_dirs, biggest_ones);
|
draw_it(
|
||||||
|
permissions,
|
||||||
|
!use_full_path,
|
||||||
|
depth,
|
||||||
|
simplified_dirs,
|
||||||
|
biggest_ones,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
+14
-2
@@ -45,7 +45,13 @@ fn main_output(short_paths: bool) -> String {
|
|||||||
{}
|
{}
|
||||||
{}",
|
{}",
|
||||||
format_string("src/test_dir", true, short_paths, " 4.0K", "─┬"),
|
format_string("src/test_dir", true, short_paths, " 4.0K", "─┬"),
|
||||||
format_string("src/test_dir/many", true, short_paths, " 4.0K", " └─┬",),
|
format_string(
|
||||||
|
"src/test_dir/many",
|
||||||
|
true,
|
||||||
|
short_paths,
|
||||||
|
" 4.0K",
|
||||||
|
" └─┬",
|
||||||
|
),
|
||||||
format_string(
|
format_string(
|
||||||
"src/test_dir/many/hello_file",
|
"src/test_dir/many/hello_file",
|
||||||
true,
|
true,
|
||||||
@@ -71,7 +77,13 @@ fn main_output(short_paths: bool) -> String {
|
|||||||
{}
|
{}
|
||||||
{}",
|
{}",
|
||||||
format_string("src/test_dir", true, short_paths, " 12K", "─┬"),
|
format_string("src/test_dir", true, short_paths, " 12K", "─┬"),
|
||||||
format_string("src/test_dir/many", true, short_paths, " 8.0K", " └─┬",),
|
format_string(
|
||||||
|
"src/test_dir/many",
|
||||||
|
true,
|
||||||
|
short_paths,
|
||||||
|
" 8.0K",
|
||||||
|
" └─┬",
|
||||||
|
),
|
||||||
format_string(
|
format_string(
|
||||||
"src/test_dir/many/hello_file",
|
"src/test_dir/many/hello_file",
|
||||||
true,
|
true,
|
||||||
|
|||||||
+3
-6
@@ -50,22 +50,21 @@ pub fn get_dir_tree(
|
|||||||
|
|
||||||
fn strip_end_slashes(s: &str) -> String {
|
fn strip_end_slashes(s: &str) -> String {
|
||||||
let mut new_name = String::from(s);
|
let mut new_name = String::from(s);
|
||||||
while new_name.chars().last() == Some('/') && new_name.len() != 1 {
|
while new_name.ends_with('/') && new_name.len() != 1 {
|
||||||
new_name.pop();
|
new_name.pop();
|
||||||
}
|
}
|
||||||
new_name
|
new_name
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examine_dir(
|
fn examine_dir(
|
||||||
top_dir: &String,
|
top_dir: &str,
|
||||||
apparent_size: bool,
|
apparent_size: bool,
|
||||||
inodes: &mut HashSet<(u64, u64)>,
|
inodes: &mut HashSet<(u64, u64)>,
|
||||||
data: &mut HashMap<String, u64>,
|
data: &mut HashMap<String, u64>,
|
||||||
permissions: &mut u64,
|
permissions: &mut u64,
|
||||||
) {
|
) {
|
||||||
for entry in WalkDir::new(top_dir) {
|
for entry in WalkDir::new(top_dir) {
|
||||||
match entry {
|
if let Ok(e) = entry {
|
||||||
Ok(e) => {
|
|
||||||
let maybe_size_and_inode = get_metadata(&e, apparent_size);
|
let maybe_size_and_inode = get_metadata(&e, apparent_size);
|
||||||
|
|
||||||
match maybe_size_and_inode {
|
match maybe_size_and_inode {
|
||||||
@@ -92,8 +91,6 @@ fn examine_dir(
|
|||||||
None => *permissions += 1,
|
None => *permissions += 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn compare_tuple(a: &(String, u64), b: &(String, u64)) -> Ordering {
|
pub fn compare_tuple(a: &(String, u64), b: &(String, u64)) -> Ordering {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ fn get_block_size() -> u64 {
|
|||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
pub fn get_metadata(d: &DirEntry, use_apparent_size: bool) -> Option<(u64, Option<(u64, u64)>)> {
|
pub fn get_metadata(d: &DirEntry, use_apparent_size: bool) -> Option<(u64, Option<(u64, u64)>)> {
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
d.metadata().ok().map_or(None, |md| {
|
d.metadata().ok().and_then(|md| {
|
||||||
let inode = Some((md.ino(), md.dev()));
|
let inode = Some((md.ino(), md.dev()));
|
||||||
if use_apparent_size {
|
if use_apparent_size {
|
||||||
Some((md.len(), inode))
|
Some((md.len(), inode))
|
||||||
|
|||||||
Reference in New Issue
Block a user