From be73d054eb3afa3075ba52053fdc79d78566b8d5 Mon Sep 17 00:00:00 2001 From: David McDonald Date: Sat, 21 Dec 2024 14:00:18 -0600 Subject: [PATCH] Clippy fixes --- src/catalog.rs | 6 ++-- src/chunks/firehose/activity.rs | 2 +- src/chunks/firehose/firehose_log.rs | 46 +++++++++++++---------------- src/chunks/firehose/flags.rs | 6 ++-- src/chunks/firehose/message.rs | 2 +- src/chunks/firehose/nonactivity.rs | 6 ++-- src/chunks/firehose/signpost.rs | 12 ++++---- src/chunks/firehose/trace.rs | 2 +- src/decoders/dns.rs | 2 +- src/filesystem.rs | 28 +++++++++--------- src/message.rs | 4 +-- src/timesync.rs | 4 +-- src/traits.rs | 4 +-- src/unified_log.rs | 2 +- 14 files changed, 60 insertions(+), 66 deletions(-) diff --git a/src/catalog.rs b/src/catalog.rs index 314f540..9bd8196 100755 --- a/src/catalog.rs +++ b/src/catalog.rs @@ -634,7 +634,7 @@ mod tests { assert_eq!(subsystems.subsystem_offset, 0); assert_eq!(subsystems.category_offset, 19); - let (_, subsystems) = CatalogChunk::parse_process_info_subystem(&data).unwrap(); + let (_, subsystems) = CatalogChunk::parse_process_info_subystem(data).unwrap(); assert_eq!(subsystems.identifer, 78); assert_eq!(subsystems.subsystem_offset, 0); assert_eq!(subsystems.category_offset, 47); @@ -667,7 +667,7 @@ mod tests { assert_eq!(subchunk.number_string_offsets, 3); assert_eq!(subchunk.string_offsets, [0, 19, 47]); - let (data, subchunk) = CatalogChunk::parse_catalog_subchunk(&data).unwrap(); + let (data, subchunk) = CatalogChunk::parse_catalog_subchunk(data).unwrap(); assert_eq!(subchunk.start, 820274802743600); assert_eq!(subchunk.end, 820313668399715); assert_eq!(subchunk.uncompressed_size, 61552); @@ -677,7 +677,7 @@ mod tests { assert_eq!(subchunk.number_string_offsets, 3); assert_eq!(subchunk.string_offsets, [0, 19, 47]); - let (_, subchunk) = CatalogChunk::parse_catalog_subchunk(&data).unwrap(); + let (_, subchunk) = CatalogChunk::parse_catalog_subchunk(data).unwrap(); assert_eq!(subchunk.start, 820313685231257); assert_eq!(subchunk.end, 820374429029888); assert_eq!(subchunk.uncompressed_size, 65536); diff --git a/src/chunks/firehose/activity.rs b/src/chunks/firehose/activity.rs index b094f46..f71d11b 100755 --- a/src/chunks/firehose/activity.rs +++ b/src/chunks/firehose/activity.rs @@ -282,7 +282,7 @@ mod tests { &firehose.firehose_activity, &string_results, &shared_strings_results, - firehose.format_string_location as u64, + u64::from(firehose.format_string_location), &preamble.first_number_proc_id, &preamble.second_number_proc_id, &catalog_data.catalog, diff --git a/src/chunks/firehose/firehose_log.rs b/src/chunks/firehose/firehose_log.rs index b33462c..f6c1875 100755 --- a/src/chunks/firehose/firehose_log.rs +++ b/src/chunks/firehose/firehose_log.rs @@ -2747,8 +2747,8 @@ mod tests { assert_eq!(firehose.base_continous_time, 4197166166425); let mut firehouse_result_count = firehose.public_data.len(); - while data.len() != 0 { - let (test_data, firehose) = FirehosePreamble::parse_firehose_preamble(&data).unwrap(); + while !data.is_empty() { + let (test_data, firehose) = FirehosePreamble::parse_firehose_preamble(data).unwrap(); data = test_data; firehouse_result_count += firehose.public_data.len(); } @@ -2786,9 +2786,8 @@ mod tests { assert_eq!(firehose.firehose_non_activity.private_strings_offset, 0); assert_eq!(firehose.firehose_non_activity.private_strings_size, 0); assert_eq!(firehose.firehose_non_activity.unknown_message_string_ref, 0); - assert_eq!( - firehose.firehose_non_activity.firehose_formatters.main_exe, - false + assert!( + !firehose.firehose_non_activity.firehose_formatters.main_exe ); assert_eq!(firehose.firehose_non_activity.subsystem_value, 14); @@ -2979,19 +2978,17 @@ mod tests { 14968 ); - assert_eq!( + assert!( firehose.public_data[0] .firehose_non_activity .firehose_formatters - .main_exe, - true + .main_exe ); - assert_eq!( - firehose.public_data[0] + assert!( + !firehose.public_data[0] .firehose_non_activity .firehose_formatters - .shared_cache, - false + .shared_cache ); assert_eq!( firehose.public_data[0] @@ -3007,12 +3004,11 @@ mod tests { .large_shared_cache, 0 ); - assert_eq!( - firehose.public_data[0] + assert!( + !firehose.public_data[0] .firehose_non_activity .firehose_formatters - .absolute, - false + .absolute ); assert_eq!( firehose.public_data[0] @@ -3021,19 +3017,17 @@ mod tests { .uuid_relative, String::new() ); - assert_eq!( - firehose.public_data[0] + assert!( + !firehose.public_data[0] .firehose_non_activity .firehose_formatters - .main_plugin, - false + .main_plugin ); - assert_eq!( - firehose.public_data[0] + assert!( + !firehose.public_data[0] .firehose_non_activity .firehose_formatters - .pc_style, - false + .pc_style ); assert_eq!( firehose.public_data[0] @@ -3396,8 +3390,8 @@ mod tests { assert_eq!(firehose.base_continous_time, 0); let mut firehouse_result_count = firehose.public_data.len(); - while data.len() != 0 { - let (test_data, firehose) = FirehosePreamble::parse_firehose_preamble(&data).unwrap(); + while !data.is_empty() { + let (test_data, firehose) = FirehosePreamble::parse_firehose_preamble(data).unwrap(); data = test_data; firehouse_result_count += firehose.public_data.len(); } diff --git a/src/chunks/firehose/flags.rs b/src/chunks/firehose/flags.rs index e128950..db7945e 100644 --- a/src/chunks/firehose/flags.rs +++ b/src/chunks/firehose/flags.rs @@ -154,7 +154,7 @@ mod tests { let test_flags = 514; let (_, results) = FirehoseFormatters::firehose_formatter_flags(&test_data, &test_flags).unwrap(); - assert_eq!(results.main_exe, true); + assert!(results.main_exe); } #[test] @@ -167,7 +167,7 @@ mod tests { let test_flags = 516; let (_, results) = FirehoseFormatters::firehose_formatter_flags(&test_data, &test_flags).unwrap(); - assert_eq!(results.shared_cache, true); + assert!(results.shared_cache); } #[test] @@ -183,7 +183,7 @@ mod tests { let test_flags = 8; let (_, results) = FirehoseFormatters::firehose_formatter_flags(&test_data, &test_flags).unwrap(); - assert_eq!(results.absolute, true); + assert!(results.absolute); assert_eq!(results.main_exe_alt_index, 65408); } diff --git a/src/chunks/firehose/message.rs b/src/chunks/firehose/message.rs index c32b0c9..7b84355 100644 --- a/src/chunks/firehose/message.rs +++ b/src/chunks/firehose/message.rs @@ -1084,7 +1084,7 @@ mod tests { let test_uuid = "B736DF1625F538248E9527A8CEC4991E"; - let (_, image_path) = MessageData::get_uuid_image_path(&test_uuid, &strings).unwrap(); + let (_, image_path) = MessageData::get_uuid_image_path(test_uuid, &strings).unwrap(); assert_eq!(image_path, "/usr/libexec/opendirectoryd"); } diff --git a/src/chunks/firehose/nonactivity.rs b/src/chunks/firehose/nonactivity.rs index f42dd41..2402888 100755 --- a/src/chunks/firehose/nonactivity.rs +++ b/src/chunks/firehose/nonactivity.rs @@ -263,8 +263,8 @@ mod tests { nonactivity_results.firehose_formatters.uuid_relative, String::from("") ); - assert_eq!(nonactivity_results.firehose_formatters.main_exe, false); - assert_eq!(nonactivity_results.firehose_formatters.absolute, false); + assert!(!nonactivity_results.firehose_formatters.main_exe); + assert!(!nonactivity_results.firehose_formatters.absolute); assert_eq!(nonactivity_results.subsystem_value, 41); assert_eq!(nonactivity_results.ttl_value, 0); assert_eq!(nonactivity_results.data_ref_value, 0); @@ -301,7 +301,7 @@ mod tests { &firehose.firehose_non_activity, &string_results, &shared_strings_results, - firehose.format_string_location as u64, + u64::from(firehose.format_string_location), &preamble.first_number_proc_id, &preamble.second_number_proc_id, &catalog_data.catalog, diff --git a/src/chunks/firehose/signpost.rs b/src/chunks/firehose/signpost.rs index 30d453d..b6ba466 100755 --- a/src/chunks/firehose/signpost.rs +++ b/src/chunks/firehose/signpost.rs @@ -271,14 +271,14 @@ mod tests { assert_eq!(results.ttl_value, 0); assert_eq!(results.data_ref_value, 0); - assert_eq!(results.firehose_formatters.main_exe, true); - assert_eq!(results.firehose_formatters.shared_cache, false); + assert!(results.firehose_formatters.main_exe); + assert!(!results.firehose_formatters.shared_cache); assert_eq!(results.firehose_formatters.has_large_offset, 0); assert_eq!(results.firehose_formatters.large_shared_cache, 0); - assert_eq!(results.firehose_formatters.absolute, false); + assert!(!results.firehose_formatters.absolute); assert_eq!(results.firehose_formatters.uuid_relative, String::new()); - assert_eq!(results.firehose_formatters.main_plugin, false); - assert_eq!(results.firehose_formatters.pc_style, false); + assert!(!results.firehose_formatters.main_plugin); + assert!(!results.firehose_formatters.pc_style); assert_eq!(results.firehose_formatters.main_exe_alt_index, 0); } @@ -306,7 +306,7 @@ mod tests { &firehose.firehose_signpost, &string_results, &shared_strings_results, - firehose.format_string_location as u64, + u64::from(firehose.format_string_location), &preamble.first_number_proc_id, &preamble.second_number_proc_id, &catalog_data.catalog, diff --git a/src/chunks/firehose/trace.rs b/src/chunks/firehose/trace.rs index f3fab4b..5bc5789 100755 --- a/src/chunks/firehose/trace.rs +++ b/src/chunks/firehose/trace.rs @@ -222,7 +222,7 @@ mod tests { if firehose.unknown_log_activity_type == activity_type { let (_, message_data) = FirehoseTrace::get_firehose_trace_strings( &string_results, - firehose.format_string_location as u64, + u64::from(firehose.format_string_location), &preamble.first_number_proc_id, &preamble.second_number_proc_id, &catalog_data.catalog, diff --git a/src/decoders/dns.rs b/src/decoders/dns.rs index 8d70d5e..348dc63 100644 --- a/src/decoders/dns.rs +++ b/src/decoders/dns.rs @@ -635,7 +635,7 @@ mod tests { fn test_get_service_binding() { let test_data = "AAEAAAEAAwJoMgAEAAhoEJRAaBCVQAAGACAmBkcAAAAAAAAAAABoEJRAJgZHAAAAAAAAAAAAaBCVQA=="; - let result = get_service_binding(&test_data).unwrap(); + let result = get_service_binding(test_data).unwrap(); assert_eq!(result, "rdata: 1 . alpn=h2, ipv4 hint:104.16.148.64,104.16.149.64, ipv6 hint:2606:4700::6810:9440,2606:4700::6810:9540"); } diff --git a/src/filesystem.rs b/src/filesystem.rs index 1580237..8262a91 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -3,7 +3,7 @@ use std::io::Read; use std::path::{Component, Path, PathBuf}; use walkdir::WalkDir; -/// Provides an implementation of [FileProvider] that enumerates the +/// Provides an implementation of [`FileProvider`] that enumerates the /// required files at the correct paths on a live macOS system. These files are only present on /// macOS Sierra (10.12) and above. The implemented methods emit error log messages if any are /// encountered while enumerating files or creating readers, but are otherwise infallible. @@ -45,7 +45,7 @@ impl From<&Path> for LogFileType { if filename_s.len() == 30 && only_hex_chars(filename_s) && parent_s.len() == 2 - && only_hex_chars(&parent_s) + && only_hex_chars(parent_s) { return Self::UUIDText; } @@ -72,7 +72,7 @@ impl FileProvider for LiveSystemProvider { .filter_map(|entry| entry.ok()) .filter(|entry| matches!(LogFileType::from(entry.path()), LogFileType::TraceV3)) .filter_map(|entry| { - Some(Box::new(std::fs::File::open(&entry.path()).ok()?) as Box) + Some(Box::new(std::fs::File::open(entry.path()).ok()?) as Box) }), ) } @@ -86,7 +86,7 @@ impl FileProvider for LiveSystemProvider { .filter(|entry| matches!(LogFileType::from(entry.path()), LogFileType::UUIDText)) .map(|entry| { ( - std::fs::File::open(&entry.path()), + std::fs::File::open(entry.path()), entry .file_name() .to_os_string() @@ -94,7 +94,7 @@ impl FileProvider for LiveSystemProvider { .into_owned(), ) }) - .filter_map(|(handle, file_name)| Some((handle.ok(), file_name))) + .map(|(handle, file_name)| (handle.ok(), file_name)) .filter_map(|(handle, file_name)| Some((handle?, file_name))) .map(|(handle, file_name)| (Box::new(handle) as Box, file_name)), ) @@ -108,7 +108,7 @@ impl FileProvider for LiveSystemProvider { .filter_map(|entry| entry.ok()) .map(|entry| { ( - std::fs::File::open(&entry.path()), + std::fs::File::open(entry.path()), entry .file_name() .to_os_string() @@ -116,7 +116,7 @@ impl FileProvider for LiveSystemProvider { .into_owned(), ) }) - .filter_map(|(handle, file_name)| Some((handle.ok(), file_name))) + .map(|(handle, file_name)| (handle.ok(), file_name)) .filter_map(|(handle, file_name)| Some((handle?, file_name))) .map(|(handle, file_name)| (Box::new(handle) as Box, file_name)), ) @@ -130,7 +130,7 @@ impl FileProvider for LiveSystemProvider { .filter_map(|entry| entry.ok()) .filter(|entry| matches!(LogFileType::from(entry.path()), LogFileType::Timesync)) .filter_map(|entry| { - Some(Box::new(std::fs::File::open(&entry.path()).ok()?) as Box) + Some(Box::new(std::fs::File::open(entry.path()).ok()?) as Box) }), ) } @@ -156,7 +156,7 @@ impl FileProvider for LogarchiveProvider { .filter_map(|entry| entry.ok()) .filter(|entry| matches!(LogFileType::from(entry.path()), LogFileType::TraceV3)) .filter_map(|entry| { - Some(Box::new(std::fs::File::open(&entry.path()).ok()?) as Box) + Some(Box::new(std::fs::File::open(entry.path()).ok()?) as Box) }), ) } @@ -169,7 +169,7 @@ impl FileProvider for LogarchiveProvider { .filter(|entry| matches!(LogFileType::from(entry.path()), LogFileType::UUIDText)) .map(|entry| { ( - std::fs::File::open(&entry.path()), + std::fs::File::open(entry.path()), entry .file_name() .to_os_string() @@ -177,7 +177,7 @@ impl FileProvider for LogarchiveProvider { .into_owned(), ) }) - .filter_map(|(handle, file_name)| Some((handle.ok(), file_name))) + .map(|(handle, file_name)| (handle.ok(), file_name)) .filter_map(|(handle, file_name)| Some((handle?, file_name))) .map(|(handle, file_name)| (Box::new(handle) as Box, file_name)), ) @@ -191,7 +191,7 @@ impl FileProvider for LogarchiveProvider { .filter(|entry| matches!(LogFileType::from(entry.path()), LogFileType::Dsc)) .map(|entry| { ( - std::fs::File::open(&entry.path()), + std::fs::File::open(entry.path()), entry .file_name() .to_os_string() @@ -199,7 +199,7 @@ impl FileProvider for LogarchiveProvider { .into_owned(), ) }) - .filter_map(|(handle, file_name)| Some((handle.ok(), file_name))) + .map(|(handle, file_name)| (handle.ok(), file_name)) .filter_map(|(handle, file_name)| Some((handle?, file_name))) .map(|(handle, file_name)| (Box::new(handle) as Box, file_name)), ) @@ -212,7 +212,7 @@ impl FileProvider for LogarchiveProvider { .filter_map(|entry| entry.ok()) .filter(|entry| matches!(LogFileType::from(entry.path()), LogFileType::Timesync)) .filter_map(|entry| { - Some(Box::new(std::fs::File::open(&entry.path()).ok()?) as Box) + Some(Box::new(std::fs::File::open(entry.path()).ok()?) as Box) }), ) } diff --git a/src/message.rs b/src/message.rs index 612f2db..ed5fdce 100755 --- a/src/message.rs +++ b/src/message.rs @@ -1366,7 +1366,7 @@ mod tests { test_format, test_width, test_precision, - &test_type, + test_type, plus_minus, hashtag, ); @@ -1385,7 +1385,7 @@ mod tests { test_format, test_width, test_precision, - &test_type, + test_type, plus_minus, hashtag, ); diff --git a/src/timesync.rs b/src/timesync.rs index 953b5df..6e5f1c8 100755 --- a/src/timesync.rs +++ b/src/timesync.rs @@ -367,7 +367,7 @@ mod tests { firehose_preamble_continous_time, 1, ); - assert_eq!(results, 1642304803060378889.0); + assert_eq!(results, 1_642_304_803_060_379_000.0); } #[test] @@ -408,6 +408,6 @@ mod tests { firehose_preamble_continous_time, 0, ); - assert_eq!(results, 1650767813342574583.0); + assert_eq!(results, 1_650_767_813_342_574_600.0); } } diff --git a/src/traits.rs b/src/traits.rs index 8cb098c..bf12033 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -4,7 +4,7 @@ use std::io::Read; /// arbitrary formats, as long as they are provided as an iterator of items that implement [Read]. /// /// For help mapping files to the correct filetype, see the -/// [LogFileType](crate::filesystem::LogFileType) enum's +/// [`LogFileType`](crate::filesystem::LogFileType) enum's /// [From]<&[Path](std::path::Path)> implementation. pub trait FileProvider { /// Provides an iterator of `.tracev3` files from the @@ -12,7 +12,7 @@ pub trait FileProvider { /// `livedata.LogData.tracev3` file if it was collected via `log collect`. fn tracev3_files(&self) -> Box>>; - /// Provides an iterator of UUIDText string files from the `/var/db/uuidtext/XX/` directories, + /// Provides an iterator of `UUIDText` string files from the `/var/db/uuidtext/XX/` directories, /// where the `XX` is any two uppercase hex characters, along with the filename (i.e., the /// filename from the _source_ file. This should be a 30-character name containing only hex /// digits. This should be a 30-character name containing only hex digits. It is important that diff --git a/src/unified_log.rs b/src/unified_log.rs index 11cd744..a3cf6c1 100755 --- a/src/unified_log.rs +++ b/src/unified_log.rs @@ -1007,7 +1007,7 @@ mod tests { assert_eq!(results.len(), 207366); assert_eq!(results[0].process, "/usr/libexec/lightsoutmanagementd"); assert_eq!(results[0].subsystem, "com.apple.lom"); - assert_eq!(results[0].time, 1642302326434850732.0); + assert_eq!(results[0].time, 1_642_302_326_434_850_800.0); assert_eq!(results[0].activity_id, 0); assert_eq!(results[0].library, "/usr/libexec/lightsoutmanagementd"); assert_eq!(results[0].library_uuid, "6C3ADF991F033C1C96C4ADFAA12D8CED");