~intltool/intltool/trunk

« back to all changes in this revision

Viewing changes to intltool-merge.in

  • Committer: Danilo Šegan
  • Date: 2017-05-23 04:14:58 UTC
  • mfrom: (747.1.1 intltool)
  • Revision ID: danilo@canonical.com-20170523041458-7ic4si3n8q1ywal2
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.

Bug #1687644: load_cache race (fix by Bernhard M. Wiedemann).

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
use Text::Wrap;
44
44
use File::Basename;
45
45
use Encode;
 
46
use Fcntl qw(:flock);
46
47
 
47
48
my $must_end_tag      = -1;
48
49
my $last_depth        = -1;
392
393
 
393
394
sub 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
398
    my $cache_file_age = -M $cache_file;
396
399
    if (defined $cache_file_age) 
397
400
    {
398
401
        if ($cache_file_age <= &get_newest_po_age) 
399
402
        {
 
403
            close($lockfh);
400
404
            &load_cache;
401
405
            return;
402
406
        }
404
408
    }
405
409
 
406
410
    &create_cache;
 
411
    close($lockfh);
407
412
}
408
413
 
409
414
sub add_translation