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
=== modified file 'intltool-merge.in'
--- intltool-merge.in 2014-11-24 02:37:01 +0000
+++ intltool-merge.in 2017-05-18 19:19:33 +0000
@@ -43,6 +43,7 @@
43use Text::Wrap;43use Text::Wrap;
44use File::Basename;44use File::Basename;
45use Encode;45use Encode;
46use Fcntl qw(:flock);
4647
47my $must_end_tag = -1;48my $must_end_tag = -1;
48my $last_depth = -1;49my $last_depth = -1;
@@ -392,11 +393,14 @@
392393
393sub get_cached_translation_database394sub get_cached_translation_database
394{395{
396 open(my $lockfh, ">", "$cache_file.lock") or die $!;
397 flock($lockfh, LOCK_EX) or die "Could not lock '$cache_file.lock' - $!";
395 my $cache_file_age = -M $cache_file;398 my $cache_file_age = -M $cache_file;
396 if (defined $cache_file_age) 399 if (defined $cache_file_age)
397 {400 {
398 if ($cache_file_age <= &get_newest_po_age) 401 if ($cache_file_age <= &get_newest_po_age)
399 {402 {
403 close($lockfh);
400 &load_cache;404 &load_cache;
401 return;405 return;
402 }406 }
@@ -404,6 +408,7 @@
404 }408 }
405409
406 &create_cache;410 &create_cache;
411 close($lockfh);
407}412}
408413
409sub add_translation414sub add_translation

Subscribers

People subscribed via source and target branches