#298: use native extensions
This commit is contained in:
parent
99d7a2baa0
commit
7c0135edc1
2
Gemfile
2
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'
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue