Merge lp:~ubuntubmw/intltool/fix-cache-race into lp:intltool

Proposed by Bernhard M. Wiedemann
Status: Merged
Approved by: Данило Шеган
Approved revision: 748
Merged at revision: 748
Proposed branch: lp:~ubuntubmw/intltool/fix-cache-race
Merge into: lp:intltool
Diff against target: 34 lines (+5/-0)
1 file modified
intltool-merge.in (+5/-0)
To merge this branch: bzr merge lp:~ubuntubmw/intltool/fix-cache-race
Reviewer Review Type Date Requested Status
Данило Шеган Approve
Review via email: mp+324278@code.launchpad.net

Description of the change

    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

To post a comment you must log in.
Revision history for this message
Данило Шеган (danilo) wrote :

Looks good, thanks for the fix!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'intltool-merge.in'
2--- intltool-merge.in 2014-11-24 02:37:01 +0000
3+++ intltool-merge.in 2017-05-18 19:19:33 +0000
4@@ -43,6 +43,7 @@
5 use Text::Wrap;
6 use File::Basename;
7 use Encode;
8+use Fcntl qw(:flock);
9
10 my $must_end_tag = -1;
11 my $last_depth = -1;
12@@ -392,11 +393,14 @@
13
14 sub get_cached_translation_database
15 {
16+ open(my $lockfh, ">", "$cache_file.lock") or die $!;
17+ flock($lockfh, LOCK_EX) or die "Could not lock '$cache_file.lock' - $!";
18 my $cache_file_age = -M $cache_file;
19 if (defined $cache_file_age)
20 {
21 if ($cache_file_age <= &get_newest_po_age)
22 {
23+ close($lockfh);
24 &load_cache;
25 return;
26 }
27@@ -404,6 +408,7 @@
28 }
29
30 &create_cache;
31+ close($lockfh);
32 }
33
34 sub add_translation

Subscribers

People subscribed via source and target branches