in reply to Re: Re: Update in-place with temporary file and flocking
in thread Update in-place with temporary file and flocking

I can not see a second read-write sequence. The operations are the same for both examples.
Boris
  • Comment on Re: Re: Re: Update in-place with temporary file and flocking

Replies are listed 'Best First'.
Re: Re: Re: Re: Update in-place with temporary file and flocking
by geohar (Acolyte) on Feb 18, 2004 at 20:00 UTC
    I may have misread/understood your code, but in order to be able to open and lock file1 wouldn't it have to be:
    copy "file1", "file2"; # instead of move my $fh = new IO::File("file1","w") flock($fh,LOCK_EX) or die "can't get lock"; my $fh2 = new IO::File("file2","r"); #read fh2 write to $fh flock($fh,LOCK_UN); # perhaps delete file2
    With the rename, even if we could create a file1 to subsequently lock, wouldn't there'd be a small gap where a program could attempt to get read access to file1 and find it not there...