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

Sure, that's what I was going to try next. I was wondering though, If I could get away without the second read-write sequence. I wanted to just rename the 2nd file over the top...
  • Comment on Re: Re: Update in-place with temporary file and flocking

Replies are listed 'Best First'.
Re: Re: Re: Update in-place with temporary file and flocking
by borisz (Canon) on Feb 18, 2004 at 18:50 UTC
    I can not see a second read-write sequence. The operations are the same for both examples.
    Boris
      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...