intltool-fixrace.patch 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. From: Bernhard M. Wiedemann <bmwiedemann+intltool@suse.de>
  2. avoid a race where some processes try to use a partial cache file
  3. that is still being written to.
  4. Note that we release the lock before load_cache,
  5. because if we got the lock, the cache is already completely written
  6. and it is OK to have multiple parallel readers
  7. Index: intltool-0.51.0/intltool-merge.in
  8. ===================================================================
  9. --- intltool-0.51.0.orig/intltool-merge.in
  10. +++ intltool-0.51.0/intltool-merge.in
  11. @@ -43,6 +43,7 @@ use Getopt::Long;
  12. use Text::Wrap;
  13. use File::Basename;
  14. use Encode;
  15. +use Fcntl qw(:flock);
  16. my $must_end_tag = -1;
  17. my $last_depth = -1;
  18. @@ -392,11 +393,14 @@ sub load_cache
  19. sub get_cached_translation_database
  20. {
  21. + open(my $lockfh, ">", "$cache_file.lock") or die $!;
  22. + flock($lockfh, LOCK_EX) or die "Could not lock '$cache_file.lock' - $!";
  23. my $cache_file_age = -M $cache_file;
  24. if (defined $cache_file_age)
  25. {
  26. if ($cache_file_age <= &get_newest_po_age)
  27. {
  28. + close($lockfh);
  29. &load_cache;
  30. return;
  31. }
  32. @@ -404,6 +408,7 @@ sub get_cached_translation_database
  33. }
  34. &create_cache;
  35. + close($lockfh);
  36. }
  37. sub add_translation