first copy to temp file, then rename