cp: wrong target path on Windows
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 24.1k
- Forks
- 2k
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 365
Description
I called cp -r W:/ \\Mac\Home\Download\dumb and the program told me W:\id.dat and W:\id.dat are the same file.
Here is some extra infos I got from debugging:
When calling cp -r W:/ \\Mac\Home\Download\dumb, I find something wrong in copydir::Entry::new : all source_relative, source_absolute, descendant and local_to_target are equal to "W:/"
This is because context.root_parent is None so get_local_to_root_parent takes the root of source_absolute. On UNIX system, this is fine because the whole system and devices are accessible from the root / (so it's a unique root system) but in the case of Windows, there are several roots (e.g. A:/, B:/, C:/, even \\ for remote folders).
Note that when calling cp -r W:/* \\Mac\Home\Download\dumb (note the glob star), paths are good because context.root_parent is Some with W:/.
So i think a fix about multiple roots case on Windows, like for example in get_local_to_root_parent when root_parent is None, remove the {Letter}:{Slash} if found.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading copydir::Entry::new and get_local_to_root_parent, then reproduce cp -r W:/ \\Mac\Home\Download\dumb on Windows. Trace how a missing context.root_parent is converted into a root path, and verify that drive-letter roots remain distinct and the command no longer reports the source and destination as the same file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100