Ensure that symlinks are moved before regular files, since this can in some cases causes a 'No such file or directory' error when the symlink target is moved before the symlink itself.
Merge with a89bbdfd4a71671d575d9a0a3a9f8abeba3f7b21