Skip to content

Commit

Permalink
Item8398: Lock all VC::Handler filesystem write access to avoir race …
Browse files Browse the repository at this point in the history
…conditions. flock should be portable nowadays

git-svn-id: http://svn.foswiki.org/trunk@7773 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
OlivierRaginel authored and OlivierRaginel committed Jun 13, 2010
1 parent 1404638 commit 61ba4f2
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions core/lib/Foswiki/Store/VC/Handler.pm
Expand Up @@ -31,6 +31,7 @@ use IO::File ();
use File::Copy ();
use File::Spec ();
use File::Path ();
use Fcntl ();

use Foswiki::Store ();
use Foswiki::Sandbox ();
Expand Down Expand Up @@ -832,17 +833,22 @@ sub saveFile {
my ( $this, $name, $text ) = @_;

$this->mkPathTo($name);
my $FILE;
open( $FILE, '>', $name )
|| throw Error::Simple(
my $fh;
open( $fh, '>', $name )
or throw Error::Simple(
'VC::Handler: failed to create file ' . $name . ': ' . $! );
binmode($FILE)
|| throw Error::Simple(
flock( $fh, Fcntl::LOCK_EX )
or throw Error::Simple(
'VC::Handler: failed to lock file ' . $name . ': ' . $! );
binmode($fh)
or throw Error::Simple(
'VC::Handler: failed to binmode ' . $name . ': ' . $! );
print $FILE $text;
close($FILE)
|| throw Error::Simple(
'VC::Handler: failed to create file ' . $name . ': ' . $! );
print $fh $text
or throw Error::Simple(
'VC::Handler: failed to print into ' . $name . ': ' . $! );
close($fh)
or throw Error::Simple(
'VC::Handler: failed to close file ' . $name . ': ' . $! );
return;
}

Expand Down

0 comments on commit 61ba4f2

Please sign in to comment.