From f585ec6696b23565c210e46aa06da4a62f7d5e04 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Thu, 22 Oct 2009 15:21:54 +0200 Subject: LangFile: Use flock()ing Doesn't guarantee that all issues related to multiple processes accessing the same file at the same time, but prevents some of them. --- lib/LangFile.pm | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/LangFile.pm') diff --git a/lib/LangFile.pm b/lib/LangFile.pm index 3c5ab1e2..e81f7f7a 100644 --- a/lib/LangFile.pm +++ b/lib/LangFile.pm @@ -2,10 +2,16 @@ package LangFile; +use strict; +use warnings; +use Fcntl qw(LOCK_SH LOCK_EX SEEK_SET); + sub new { my($class, $action, $file) = @_; open my $F, $action eq 'read' ? '<:utf8' : '>:utf8', $file or die "Opening $file: $!"; + flock($F, $action eq 'read' ? LOCK_SH : LOCK_EX) or die "Locking $file: $!"; + seek($F, 0, SEEK_SET) or die "Seeking $file: $!"; return bless { act => $action, FH => $F, -- cgit v1.2.3