summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-10-22 15:21:54 +0200
committerYorhel <git@yorhel.nl>2009-10-22 15:23:08 +0200
commitf585ec6696b23565c210e46aa06da4a62f7d5e04 (patch)
treead7c6c40202fd8e3553df857dcbcdb8ea22f96f3
parent4170cec21986540ffe0f9025840971ccea682268 (diff)
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.
-rw-r--r--lib/LangFile.pm6
1 files changed, 6 insertions, 0 deletions
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,