diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 046ac6a8730..639babccb9c 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1482,7 +1482,7 @@ pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult for source in sources { let normalized_source = normalize_path(source); - if options.backup == BackupMode::None && seen_sources.contains(&normalized_source) { + if options.backup == BackupMode::None && !seen_sources.insert(normalized_source) { let file_type = if source.symlink_metadata()?.file_type().is_dir() { "directory" } else { @@ -1538,7 +1538,6 @@ pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult copied_destinations.insert(dest.clone()); } } - seen_sources.insert(normalized_source); } if let Some(pb) = progress_bar { diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 4cbd67ddc49..48dff14064f 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -538,11 +538,11 @@ fn safe_du( } // Handle inodes - if let Some(inode) = this_stat.inode { - if seen_inodes.contains(&inode) && !options.count_links { - continue; - } - seen_inodes.insert(inode); + if let Some(inode) = this_stat.inode + && !seen_inodes.insert(inode) + && !options.count_links + { + continue; } // Process directories recursively @@ -702,14 +702,11 @@ fn du_regular( } } - if let Some(inode) = this_stat.inode { - // Check if the inode has been seen before and if we should skip it - if seen_inodes.contains(&inode) && !options.count_links { - // Skip further processing for this inode - continue; - } - // Mark this inode as seen - seen_inodes.insert(inode); + if let Some(inode) = this_stat.inode + && !seen_inodes.insert(inode) + && !options.count_links + { + continue; } if this_stat.metadata.is_dir() { @@ -1202,11 +1199,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let stat = Stat::new(&path, None, &traversal_options); if let Ok(stat) = stat.as_ref() && let Some(inode) = stat.inode + && !traversal_options.count_links + && !seen_inodes.insert(inode) { - if !traversal_options.count_links && seen_inodes.contains(&inode) { - continue 'loop_file; - } - seen_inodes.insert(inode); + continue 'loop_file; } if use_safe_traversal { diff --git a/src/uu/hostname/src/hostname.rs b/src/uu/hostname/src/hostname.rs index da1adeb58ac..1c06c944335 100644 --- a/src/uu/hostname/src/hostname.rs +++ b/src/uu/hostname/src/hostname.rs @@ -101,7 +101,7 @@ fn display_hostname(matches: &ArgMatches) -> UResult<()> { let mut output = String::new(); for addr in addresses { // XXX: not sure why this is necessary... - if !hashset.contains(&addr) { + if hashset.insert(addr) { let mut ip = addr.to_string(); if ip.ends_with(":1") { let len = ip.len(); @@ -109,7 +109,6 @@ fn display_hostname(matches: &ArgMatches) -> UResult<()> { } output.push_str(&ip); output.push(' '); - hashset.insert(addr); } } let len = output.len();