Skip to content

cp and copydir shared loop drift #14342

Description

@meghuizen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions