Home > Archive > PERL Beginners > August 2005 > open and edit file to prevent race conditions
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
open and edit file to prevent race conditions
|
|
| Brent Clark 2005-08-29, 3:55 am |
| 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 s 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
| |
| John W. Krahn 2005-08-29, 7:55 am |
| Brent Clark wrote:
> Hi List
Hello,
> 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 s 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.
Which operating system is this file on? Do you have ACLs or some such
security to guaranty file locking?
John
--
use Perl;
program
fulfillment
| |
| Brent Clark 2005-08-29, 9:55 pm |
| John W. Krahn wrote:
>
> Which operating system is this file on? Do you have ACLs or some such
> security to guaranty file locking?
>
>
> John
Hi John
Thanks for replying to my email.
The file is a CSV file and so it will sit on Linux and sometimes a Win32 machine.
In terms of the file locking, I just use flock as well as the modules Fcntl.
Kind Regards
Brent Clark
|
|
|
|
|