mv: Use rustc-hash

This commit is contained in:
oech3
2026-02-18 21:08:41 +09:00
committed by Daniel Hofstetter
parent 8c98b152c6
commit 65060418dd
9 changed files with 29 additions and 20 deletions
Generated
+9 -6
View File
@@ -562,6 +562,7 @@ dependencies = [
"regex",
"rlimit",
"rstest",
"rustc-hash",
"selinux",
"sha1",
"tempfile",
@@ -984,7 +985,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
@@ -1685,7 +1686,7 @@ dependencies = [
"portable-atomic",
"portable-atomic-util",
"serde_core",
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
@@ -1982,7 +1983,7 @@ version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
@@ -2572,7 +2573,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys",
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
@@ -2872,7 +2873,7 @@ dependencies = [
"getrandom 0.3.4",
"once_cell",
"rustix",
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
@@ -3726,6 +3727,7 @@ dependencies = [
"fs_extra",
"indicatif",
"libc",
"rustc-hash",
"tempfile",
"thiserror 2.0.18",
"uucore",
@@ -4414,6 +4416,7 @@ dependencies = [
"num-traits",
"os_display",
"procfs",
"rustc-hash",
"selinux",
"sha1",
"sha2",
@@ -4600,7 +4603,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
+1
View File
@@ -559,6 +559,7 @@ num-prime.workspace = true
pretty_assertions = "1.4.0"
rand.workspace = true
regex.workspace = true
rustc-hash.workspace = true
sha1 = { workspace = true, features = ["std"] }
tempfile.workspace = true
time = { workspace = true, features = ["local-offset"] }
+1
View File
@@ -1960,6 +1960,7 @@ dependencies = [
"num-traits",
"os_display",
"procfs",
"rustc-hash",
"sha1",
"sha2",
"sha3",
+1
View File
@@ -23,6 +23,7 @@ clap = { workspace = true }
fs_extra = { workspace = true }
indicatif = { workspace = true }
libc = { workspace = true }
rustc-hash = { workspace = true }
thiserror = { workspace = true }
uucore = { workspace = true, features = [
"backup-control",
+3 -3
View File
@@ -9,7 +9,7 @@
//! This module provides functionality to preserve hardlink relationships
//! when moving files across different filesystems/partitions.
use std::collections::HashMap;
use rustc_hash::FxHashMap;
use std::io;
use std::path::{Path, PathBuf};
@@ -19,14 +19,14 @@ use uucore::display::Quotable;
#[derive(Debug, Default)]
pub struct HardlinkTracker {
/// Maps (device, inode) -> destination path for the first occurrence
inode_map: HashMap<(u64, u64), PathBuf>,
inode_map: FxHashMap<(u64, u64), PathBuf>,
}
/// Pre-scans files to identify hardlink groups with optimized memory usage
#[derive(Debug, Default)]
pub struct HardlinkGroupScanner {
/// Maps (device, inode) -> list of source paths that are hardlinked together
hardlink_groups: HashMap<(u64, u64), Vec<PathBuf>>,
hardlink_groups: FxHashMap<(u64, u64), Vec<PathBuf>>,
/// List of source files/directories being moved (for destination mapping)
source_files: Vec<PathBuf>,
/// Whether scanning has been performed
+5 -4
View File
@@ -15,8 +15,8 @@ use clap::{Arg, ArgAction, ArgMatches, Command};
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
#[cfg(all(unix, not(any(target_os = "macos", target_os = "redox"))))]
use std::collections::HashMap;
use std::collections::HashSet;
use rustc_hash::FxHashMap;
use rustc_hash::FxHashSet;
use std::env;
use std::ffi::OsString;
use std::fs;
@@ -575,7 +575,8 @@ pub fn mv(files: &[OsString], opts: &Options) -> UResult<()> {
#[allow(clippy::cognitive_complexity)]
fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, options: &Options) -> UResult<()> {
// remember the moved destinations for further usage
let mut moved_destinations: HashSet<PathBuf> = HashSet::with_capacity(files.len());
let mut moved_destinations: FxHashSet<PathBuf> =
FxHashSet::with_capacity_and_hasher(files.len(), rustc_hash::FxBuildHasher);
// Create hardlink tracking context
#[cfg(unix)]
let (mut hardlink_tracker, hardlink_scanner) = {
@@ -967,7 +968,7 @@ fn rename_dir_fallback(
};
#[cfg(all(unix, not(any(target_os = "macos", target_os = "redox"))))]
let xattrs = fsxattr::retrieve_xattrs(from).unwrap_or_else(|_| HashMap::new());
let xattrs = fsxattr::retrieve_xattrs(from).unwrap_or_else(|_| FxHashMap::default());
// Use directory copying (with or without hardlink support)
let result = copy_dir_contents(
+1
View File
@@ -36,6 +36,7 @@ jiff = { workspace = true, optional = true, features = [
"tzdb-zoneinfo",
"tzdb-concatenated",
] }
rustc-hash = { workspace = true }
time = { workspace = true, optional = true, features = [
"formatting",
"local-offset",
+5 -5
View File
@@ -7,7 +7,7 @@
//! Set of functions to manage xattr on files and dirs
use itertools::Itertools;
use std::collections::HashMap;
use rustc_hash::FxHashMap;
use std::ffi::{OsStr, OsString};
#[cfg(unix)]
use std::os::unix::ffi::OsStrExt;
@@ -54,8 +54,8 @@ pub fn copy_xattrs_skip_selinux<P: AsRef<Path>>(source: P, dest: P) -> std::io::
/// # Returns
///
/// A result containing a HashMap of attributes names and values, or an error.
pub fn retrieve_xattrs<P: AsRef<Path>>(source: P) -> std::io::Result<HashMap<OsString, Vec<u8>>> {
let mut attrs = HashMap::new();
pub fn retrieve_xattrs<P: AsRef<Path>>(source: P) -> std::io::Result<FxHashMap<OsString, Vec<u8>>> {
let mut attrs = FxHashMap::default();
for attr_name in xattr::list(&source)? {
if let Some(value) = xattr::get(&source, &attr_name)? {
attrs.insert(attr_name, value);
@@ -76,7 +76,7 @@ pub fn retrieve_xattrs<P: AsRef<Path>>(source: P) -> std::io::Result<HashMap<OsS
/// A result indicating success or failure.
pub fn apply_xattrs<P: AsRef<Path>>(
dest: P,
xattrs: HashMap<OsString, Vec<u8>>,
xattrs: FxHashMap<OsString, Vec<u8>>,
) -> std::io::Result<()> {
for (attr, value) in xattrs {
xattr::set(&dest, &attr, &value)?;
@@ -207,7 +207,7 @@ mod tests {
File::create(&file_path).unwrap();
let mut test_xattrs = HashMap::new();
let mut test_xattrs = FxHashMap::default();
let test_attr = "user.test_attr";
let test_value = b"test value";
test_xattrs.insert(OsString::from(test_attr), test_value.to_vec());
+3 -2
View File
@@ -310,13 +310,14 @@ fn test_recursive_reporting() {
// TODO Enable and modify this for freebsd when xattr processing for freebsd is enabled.
#[cfg(target_os = "linux")]
fn test_mkdir_acl() {
use std::{collections::HashMap, ffi::OsString};
use rustc_hash::FxHashMap;
use std::ffi::OsString;
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("a");
let mut map: HashMap<OsString, Vec<u8>> = HashMap::new();
let mut map: FxHashMap<OsString, Vec<u8>> = FxHashMap::default();
// posix_acl entries are in the form of
// struct posix_acl_entry{
// tag: u16,