It's possible to prevent the race, but that's probably not necessary in this simple case. I'd recommend just adding a comment that there's a race condition in that method.
I agree, after all, in that case A would just recreate the new file after that. Obviously we don;t want C to come along in the microsecond that takes, but chances are small.
There's a race condition:
It's possible to prevent the race, but that's probably not necessary in this simple case. I'd recommend just adding a comment that there's a race condition in that method.