open and edit file to prevent race conditions



Hi List

I have a scenario / debate if you wish with my colleague.

The problem is I have to update a CSV file and the way I do it open the file while reading / editting it I then send it to a temp file, unlink the original and the rename the temp
to the original file name (Baring in mind I do flock the file)

My colleague, disagrees with my approach to this, he  is adamant  that I must open the file get the file in memory and use seek etc to update the file (also using flock etc.)

So basically from the millisecond it takes to unlock ,  close, unlink, and then rename the file, I am open to race condition.

So my question is, whats the best what to update / amend a file.

Your tips and or advice, would great fully be appreciated.

Kind Regards
Brent Clark

.