Yep, it's the same race condition (though with a smaller window). The point is that you can't atomically check that a file exists and stat it, so you've got to just try and catch the failure.

I agree that it's not the prettiest.