Implement the replace-file functionality