When a directory is moved across filesystems, mv falls back to copying it, and each destination entry is created by joining a path, with regular files going through fs::copy. If a symlink appears at one of those names in the destination while the copy is running, it is followed, so that file's content (and the truncation before it) lands wherever the symlink points.
To reproduce, move a directory with many files from one filesystem to another (e.g. into /dev/shm) while another process keeps creating symlinks at the destination names, pointing at a file outside the tree. That file ends up overwritten with the source content.
When a directory is moved across filesystems, mv falls back to copying it, and each destination entry is created by joining a path, with regular files going through
fs::copy. If a symlink appears at one of those names in the destination while the copy is running, it is followed, so that file's content (and the truncation before it) lands wherever the symlink points.To reproduce, move a directory with many files from one filesystem to another (e.g. into
/dev/shm) while another process keeps creating symlinks at the destination names, pointing at a file outside the tree. That file ends up overwritten with the source content.