Firmed up copy_file checking and added a test.