From f28a6f1f3460252a7e7fe4b8e4a1ef150e587f38 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 1 Dec 2025 20:02:13 +0800 Subject: Replace HashMap/HashSet with BTreeMap/BTreeSet for deterministic output --- src/bin/jv.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/bin') diff --git a/src/bin/jv.rs b/src/bin/jv.rs index 8901a94..22fbd83 100644 --- a/src/bin/jv.rs +++ b/src/bin/jv.rs @@ -1300,6 +1300,7 @@ async fn jv_here(_args: HereArgs) { let mut file_count = 0; let mut total_size = 0; + // Exists files if let Ok(mut entries) = fs::read_dir(&path).await { while let Ok(Some(entry)) = entries.next_entry().await { if let Ok(file_type) = entry.file_type().await { @@ -1464,6 +1465,7 @@ async fn jv_here(_args: HereArgs) { } } + // Remote Files for mapping in remote_files { if let Some(metadata) = mapping.1 { let mut hold = "-".to_string(); @@ -3496,18 +3498,19 @@ fn sort_paths(paths: &mut Vec) { a.cmp(b) as i32 }); } + /// Get paths that exist in the Cached Sheet under the current directory fn mapping_names_here( current_dir: &PathBuf, local_dir: &PathBuf, cached_sheet: &SheetData, -) -> HashMap> { +) -> std::collections::BTreeMap> { let Ok(relative_path) = current_dir.strip_prefix(local_dir) else { - return HashMap::new(); + return std::collections::BTreeMap::new(); }; // Collect files directly under current directory - let files_here: HashMap> = cached_sheet + let files_here: std::collections::BTreeMap> = cached_sheet .mapping() .iter() .filter_map(|(f, mapping)| { @@ -3521,7 +3524,7 @@ fn mapping_names_here( .collect(); // Collect directories that appear in the mapping - let mut dirs_set = std::collections::HashSet::new(); + let mut dirs_set = std::collections::BTreeSet::new(); for (f, _mapping) in cached_sheet.mapping().iter() { // Get all parent directories of the file relative to the current directory @@ -3544,7 +3547,7 @@ fn mapping_names_here( } // Filter out directories that are actually files - let filtered_dirs: HashMap> = dirs_set + let filtered_dirs: std::collections::BTreeMap> = dirs_set .into_iter() .filter(|dir_with_slash| { let dir_name = dir_with_slash.trim_end_matches('/'); -- cgit