Fix possible exception when deleting a file.