Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
1 change: 1 addition & 0 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/uu/mv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/uu/mv/src/hardlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) = {
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/uucore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions src/uucore/src/lib/features/fsxattr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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)?;
Expand Down Expand Up @@ -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());
Expand Down
5 changes: 3 additions & 2 deletions tests/by-util/test_mkdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading