Package: gem2deb
Version: 0.30.1
Tags: patch

When two gem2deb processes are executed by the same user concurrently
(e.g. in a CI system building many packages), the Gem2Deb::DhMakeRuby
class can raise an error when updating its gem_to_package_data cache:

-- Creating Debian source package from ./apipie-bindings-0.2.0.tar.gz ...
/usr/lib/ruby/vendor_ruby/gem2deb/dh_make_ruby.rb:149:in `stat': No such
file or directory @ rb_file_s_stat -
/home/jenkins/.cache/gem2deb/gem_to_packages.yaml.new (Errno::ENOENT)
        from /usr/lib/ruby/vendor_ruby/gem2deb/dh_make_ruby.rb:149:in
`generate_or_update_gem_to_package_data'
        from /usr/lib/ruby/vendor_ruby/gem2deb/dh_make_ruby.rb:66:in 
`initialize'
        from ../../gem2deb:96:in `new'
        from ../../gem2deb:96:in `<main>'

It appears that both processes might be running the `apt-file` command,
redirecting into the same .new file and then only one succeeds in moving
the file, while the other fails to either stat or mv it.

Patch against version 0.33.1 attached, which uses a separate temporary
cache file per process, so it doesn't matter if another process is also
updating the same cache.

-- 
Dominic Cleal
domi...@cleal.org
--- lib/gem2deb/dh_make_ruby.rb.orig	2017-05-12 13:21:53.381044007 +0100
+++ lib/gem2deb/dh_make_ruby.rb	2017-05-12 13:23:06.368255601 +0100
@@ -144,11 +144,11 @@
       end
 
       if update
-        new_cache = cache + '.new'
+        new_cache = cache + ".new.#{$$}"
         if system('apt-file search /usr/share/rubygems-integration/ > ' + new_cache)
           if File.stat(new_cache).size > 0
             system('sed', '-i', '-e', 's#/.*/##; s/-[0-9.]\+.gemspec//', new_cache)
-            FileUtils.mv(cache + '.new', cache)
+            FileUtils.mv(new_cache, cache)
           else
             puts 'E: dh-make-ruby needs an up-to-date apt-file cache in order to map gem names'
             puts 'E: to package names but apt-file has an invalid cache. Please run '

Reply via email to