coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

cp and copydir shared loop drift

Open meghuizen opened this issue 3 months ago • 0 comments

src/uu/cp/src/cp.rs:1614-1625:

if options.parents {
    for (x, y) in aligned_ancestors(source, dest.as_path()) {
        if let Ok(src) = canonicalize(x, MissingHandling::Normal, ResolveMode::Physical) {
            copy_attributes(&src, y, &options.attributes, false, options.set_selinux_context)?;
        }
    }
}

src/uu/cp/src/copydir.rs:596-610:

if options.parents {
    let dest = root.file_name()
        .map_or_else(|| target.to_path_buf(), |name| target.join(name));
    for (x, y) in aligned_ancestors(root, dest.as_path()) {
        if let Ok(src) = canonicalize(x, MissingHandling::Normal, ResolveMode::Physical) {
            copy_attributes(&src, y, &options.attributes, false, options.set_selinux_context)?;
            #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
            ...
        }
    }
}

Same aligned_ancestors walk, same canonicalize per ancestor, same copy_attributes call with the same five arguments. The copies have already drifted: the copydir version carries an extra SELinux block the cp.rs version does not

meghuizen avatar Sep 01 '26 03:09 meghuizen