bug with os.rename in 2.4.1?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri May 1 05:11:22 EDT 2009


On Thu, 30 Apr 2009 03:30:04 -0500, Nick Craig-Wood wrote:

>>  The race condition is still there. The only difference is that in the
>>  first case it fails noisily, with an exception, and in the second it
>>  fails quietly and does nothing.
> 
> I'd argue that since os.rename implements the syscall rename() and that
> is defined to be atomic (give or take) then the above is atomic and
> can't possibly be racy.

Ah, you're right, at least for systems where rename is atomic.

What I was trying to say is that the risk of the file *not* being renamed 
is still there, but in the first case the code failed noisily with an 
exception and in the second it just failed quietly. But that's wrong, the 
test is to see if the source file exists, not whether the destination 
file exists. If the destination file exists, and you have write-access to 
it, then it will be over-written no matter what.


-- 
Steven



More information about the Python-list mailing list