In reviewing that patch I discovered that there's a similar bug in copy-file, and that there's some opportunity to simplify and robustify the rename-file code. I installed the attached patches on master to do that.