The script uses a copy to a directory name, docker cp. This appears to have the same irritating semantics as cp: copy into the directory if it exists. This means that you end up with .cargo/.cargo if .cargo already existed.
This can happen if your cache was damaged for instance if you attempted make clean_all while some files had root:root permissions. This state is actually quite common given that we are using docker to populate the cache.
Potentialy fixes
- Delete the directories before trying to copy and fail if that fails.
- Copy into a temporary and use a careful copy command (or
rsync has ways to do this because it interprets a trailing / in a useful way, but that adds a dependency) that always does the correct copy. (cp --no-target-directory might help, though I don't know quite how that works.)