mcst-linux-kernel/patches-2024.06.26/intltool-0.51.0/0001-Avoid-a-race-where-som...

58 lines
1.6 KiB
Diff

From 97c9854c9ffe34d5fb4c8e928530c9a41b8e1a35 Mon Sep 17 00:00:00 2001
From: "Bernhard M. Wiedemann" <bmwiedemann+bzrcommit@suse.de>
Date: Thu, 18 May 2017 21:09:18 +0200
Origin: https://bazaar.launchpad.net/~intltool/intltool/trunk/revision/748
https://bugs.launchpad.net/intltool/+bug/1687644
Subject: [PATCH] Avoid a race where some processes try to use a partial cache
file that is still being written to. Note that we release the lock before
load_cache, because if we got the lock, the cache is already completely
written and it is OK to have multiple parallel readers
Without this patch, translation files would randomly miss translations
for some or all languages.
fixes bug #1687644
maybe also bug #986897
---
intltool-merge.in | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/intltool-merge.in b/intltool-merge.in
index 05db7cf..89923a7 100644
--- a/intltool-merge.in
+++ b/intltool-merge.in
@@ -43,6 +43,7 @@ use Getopt::Long;
use Text::Wrap;
use File::Basename;
use Encode;
+use Fcntl qw(:flock);
my $must_end_tag = -1;
my $last_depth = -1;
@@ -392,11 +393,14 @@ sub load_cache
sub get_cached_translation_database
{
+ open(my $lockfh, ">", "$cache_file.lock") or die $!;
+ flock($lockfh, LOCK_EX) or die "Could not lock '$cache_file.lock' - $!";
my $cache_file_age = -M $cache_file;
if (defined $cache_file_age)
{
if ($cache_file_age <= &get_newest_po_age)
{
+ close($lockfh);
&load_cache;
return;
}
@@ -404,6 +408,7 @@ sub get_cached_translation_database
}
&create_cache;
+ close($lockfh);
}
sub add_translation
--
2.20.1