Fix os.Rename cross-device issue

Copy first and then delete the stage file instead of os.Rename.