diff --git a/src/parser.rs b/src/parser.rs index b526785..09cc789 100755 --- a/src/parser.rs +++ b/src/parser.rs @@ -98,14 +98,12 @@ pub fn build_log( /// Parse all UUID files in provided directory. The directory should follow the same layout as the live system (ex: path/to/files//) pub fn collect_strings(path: &str) -> Result, ParserError> { - let paths_results = fs::read_dir(path); - - let paths = paths_results.map_err(|err| { + let paths = fs::read_dir(path).map_err(|err| { error!("[macos-unifiedlogs] Failed to read directory path: {err:?}"); ParserError::Dir })?; - let mut entries = paths + let entries = paths .flat_map(|path| { path.inspect_err(|err| { error!("[macos-unifiedlogs] Failed to get directory entry: {err:?}",) @@ -113,7 +111,6 @@ pub fn collect_strings(path: &str) -> Result, ParserError> { .ok() }) .collect::>(); - entries.sort_by(|a, b| a.file_name().as_os_str().cmp(b.file_name().as_os_str())); let mut uuidtext_vec: Vec = Vec::with_capacity(entries.len()); // Start process to read a directory containing subdirectories that contain the uuidtext files @@ -440,21 +437,24 @@ mod tests { let mut test_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); test_path.push("tests/test_data/system_logs_big_sur.logarchive"); - let strings_results = collect_strings(&test_path.display().to_string()).unwrap(); + let mut strings_results = collect_strings(&test_path.display().to_string()).unwrap(); assert_eq!(strings_results.len(), 536); + + strings_results.sort_by(|a, b| a.uuid.cmp(&b.uuid)); + assert_eq!(strings_results[0].signature, 1719109785); - assert_eq!(strings_results[0].uuid, "B6B65F4DC53ED38FEB0DDF61809853"); - assert_eq!(strings_results[0].entry_descriptors.len(), 2); - assert_eq!(strings_results[0].footer_data.len(), 1707); - assert_eq!(strings_results[0].number_entries, 2); + assert_eq!(strings_results[0].uuid, "004EAF1C2B310DA0383BE3D60B80E8"); + assert_eq!(strings_results[0].entry_descriptors.len(), 1); + assert_eq!(strings_results[0].footer_data.len(), 2847); + assert_eq!(strings_results[0].number_entries, 1); assert_eq!(strings_results[0].unknown_minor_version, 1); assert_eq!(strings_results[0].unknown_major_version, 2); - assert_eq!(strings_results[1].uuid, "D9B97EA2CD39C7A9AF1888E041B9E1"); - assert_eq!(strings_results[1].footer_data.len(), 238974); + assert_eq!(strings_results[1].uuid, "00B3D870FB3AE8BDC1BA3A60D0B9A0"); + assert_eq!(strings_results[1].footer_data.len(), 2164); - assert_eq!(strings_results[2].uuid, "2578ECF07936A6A882574764C7C785"); - assert_eq!(strings_results[2].footer_data.len(), 68714); + assert_eq!(strings_results[2].uuid, "014C44534A3A748476ABD88D376918"); + assert_eq!(strings_results[2].footer_data.len(), 19011); } #[test]