File renaming should be the last operation of an atomic write

That way there is just no possible race conditions.

cc @wisq
According to the documentation it's up to the caller to ensure that. But that's a good point.