uutils / uutils/coreutils

cp and copydir shared loop drift

Open
#14,342 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - cp
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the cited loops in src/uu/cp/src/cp.rs:1614-1625 and src/uu/cp/src/copydir.rs:596-610, then inspect how their SELinux configuration affects the shared behavior. Refactor the duplicated ancestor-walk logic so the implementations cannot drift, while preserving the platform-specific block; done means both paths use consistent logic and the relevant checks pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.