diff --git a/Gemfile b/Gemfile index bc1ea4404..706507a64 100644 --- a/Gemfile +++ b/Gemfile @@ -56,6 +56,8 @@ gem 'friendly_id' gem 'rack-throttle' gem 'rest-client', '~> 1.6.6' +gem 'ffi' + gem 'attr_encrypted', '1.2.1' gem "gemoji", "~> 1.2.1", require: 'emoji/railtie' diff --git a/Gemfile.lock b/Gemfile.lock index 7b1356941..76481cbb6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -449,6 +449,7 @@ DEPENDENCIES devise (~> 2.2.3) diff-display (~> 0.0.1) factory_girl_rails (~> 4.0.0) + ffi friendly_id gemoji (~> 1.2.1) github-linguist (~> 2.3.4) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index b07a1918b..dd4ebf109 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -283,21 +283,8 @@ class BuildList < ActiveRecord::Base def has_new_packages? if last_bl = last_published.joins(:source_packages).where(:build_list_packages => {:actual => true}).last source_packages.each do |nsp| - # priority: EPOCH => VERSION => RELEASE - # TODO: EPOCH sp = last_bl.source_packages.find{ |sp| nsp.name == sp.name } - return true unless sp - sp_version = sp.version.split(/\D/).map(&:to_i) - nsp_version = nsp.version.split(/\D/).map(&:to_i) - if nsp_version == sp_version - return true if nsp.release.to_i > sp.release.to_i - else - nsp_version.each_with_index do |nv, index| - ov = sp_version[index].to_i - return true if nv > ov - return false if nv < ov - end - end + return !sp || nsp.rpmvercmp(sp) == 1 end else return true # no published packages diff --git a/app/models/build_list/package.rb b/app/models/build_list/package.rb index 1c10fb531..d176543f7 100644 --- a/app/models/build_list/package.rb +++ b/app/models/build_list/package.rb @@ -5,6 +5,7 @@ class BuildList::Package < ActiveRecord::Base belongs_to :project belongs_to :platform + attr_accessor :epoch attr_accessible :fullname, :name, :release, :version, :sha1 validates :build_list_id, :project_id, :platform_id, :fullname, @@ -25,4 +26,20 @@ class BuildList::Package < ActiveRecord::Base def assignee project.maintainer end + + def rpmvercmp(other) + RPM::C.rpmvercmp to_vre_epoch_zero, other.to_vre_epoch_zero + end + + protected + + # String representation in the form "e:v-r" + # @return [String] + # @note The epoch is included always. As 0 if not present + def to_vre_epoch_zero + evr = epoch.present? ? "#{epoch.to_i}:#{version}" : "0:#{version}" + evr << "-#{release}" if release.present? + evr + end + end diff --git a/lib/plugins/rpm.rb b/lib/plugins/rpm.rb new file mode 100644 index 000000000..5a28dd869 --- /dev/null +++ b/lib/plugins/rpm.rb @@ -0,0 +1,20 @@ +require 'ffi' + +module RPM + module C + + extend ::FFI::Library + + begin + ffi_lib ['rpm', 'librpm.so.2', 'librpm.so.1'] + rescue LoadError => e + raise( + "Can't find rpm libs on your system: #{e.message}" + ) + end + + + attach_function 'rpmvercmp', [:string, :string], :int + + end +end \ No newline at end of file