make creation of a statefile atomic