diff --git a/.gitignore b/.gitignore index f64162cf5..eba8c3256 100644 --- a/.gitignore +++ b/.gitignore @@ -19,8 +19,11 @@ .DS_Store ._* *~ +*.sw* +*.patch config/newrelic.yml public/sitemap*.xml.gz +spec/examples.txt dump.rdb db/sphinx/* config/development.sphinx.conf diff --git a/.ruby-version b/.ruby-version index 73462a5a1..aa485ac6f 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.5.1 +ext-ruby-2.5.1 diff --git a/Gemfile b/Gemfile index d4570a278..7c5aaed83 100644 --- a/Gemfile +++ b/Gemfile @@ -44,6 +44,9 @@ gem 'browser' gem 'http_accept_language' # gem 'molinillo', require: false +# view +gem 'slim' + group :production, :development do gem 'redis' end diff --git a/Gemfile.lock b/Gemfile.lock index c0aadde24..97329ccca 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -378,6 +378,9 @@ GEM simplecov-html (0.10.2) sitemap_generator (6.0.1) builder (~> 3.0) + slim (3.0.9) + temple (>= 0.7.6, < 0.9) + tilt (>= 1.3.3, < 2.1) spring (2.0.2) activesupport (>= 4.2) spring-commands-rspec (1.0.4) @@ -399,6 +402,7 @@ GEM net-scp (>= 1.1.2) net-ssh (>= 2.8.0) swagger-blocks (2.0.2) + temple (0.8.0) text (1.3.1) thor (0.20.0) thread_safe (0.3.6) @@ -514,6 +518,7 @@ DEPENDENCIES sidekiq simplecov sitemap_generator + slim spring spring-commands-rspec spring-commands-rubocop diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 46b20359f..1c9ab932e 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,3 +13,20 @@ //= require rails-ujs //= require turbolinks //= require_tree . +// + +let changeHref = (e) => { + let index = e.target.options.selectedIndex, + url = e.target.options[index].getAttribute('value') + + document.querySelectorAll('a.download').forEach((a) => { + let href = a.getAttribute('data-path') + + a.setAttribute('href', url + href) + }) +} + +document.addEventListener('DOMContentLoaded', () => { + let input = document.querySelector('.mirror-url') + input.addEventListener('change', changeHref) +}) diff --git a/app/assets/javascripts/br/local.js.erb b/app/assets/javascripts/br/local.js.erb index e5ee1e7f4..33db6e05b 100644 --- a/app/assets/javascripts/br/local.js.erb +++ b/app/assets/javascripts/br/local.js.erb @@ -1,3 +1,4 @@ +/* $(document).ready(function() { $('#topMain').toggle(function() { $('#topMain').attr("src", "<%= asset_path 'restore.gif' %>"); @@ -39,3 +40,4 @@ $(document).ready(function() { $('#topBranchesDiv').show(); }); }); +*/ diff --git a/app/assets/javascripts/en/local.js.erb b/app/assets/javascripts/en/local.js.erb index e5ee1e7f4..33db6e05b 100644 --- a/app/assets/javascripts/en/local.js.erb +++ b/app/assets/javascripts/en/local.js.erb @@ -1,3 +1,4 @@ +/* $(document).ready(function() { $('#topMain').toggle(function() { $('#topMain').attr("src", "<%= asset_path 'restore.gif' %>"); @@ -39,3 +40,4 @@ $(document).ready(function() { $('#topBranchesDiv').show(); }); }); +*/ diff --git a/app/assets/javascripts/ru/local.js.erb b/app/assets/javascripts/ru/local.js.erb index f6ff3b628..08627f01e 100644 --- a/app/assets/javascripts/ru/local.js.erb +++ b/app/assets/javascripts/ru/local.js.erb @@ -1,3 +1,4 @@ +/* $(document).ready(function() { $('#topMain').toggle(function() { $('#topMain').attr("src", "<%= asset_path 'restore.gif' %>"); @@ -39,3 +40,4 @@ $(document).ready(function() { $('#topBranchesDiv').show(); }); }); +*/ diff --git a/app/assets/javascripts/uk/local.js.erb b/app/assets/javascripts/uk/local.js.erb index 5a4c482b0..5561abbd8 100644 --- a/app/assets/javascripts/uk/local.js.erb +++ b/app/assets/javascripts/uk/local.js.erb @@ -1,3 +1,4 @@ +/* $(document).ready(function() { $('#topMain').toggle(function() { $('#topMain').attr("src", "<%= asset_path 'restore.gif' %>"); @@ -39,3 +40,4 @@ $(document).ready(function() { $('#topBranchesDiv').show(); }); }); +*/ diff --git a/app/assets/stylesheets/srpm.scss b/app/assets/stylesheets/srpm.scss new file mode 100644 index 000000000..9a7e9affc --- /dev/null +++ b/app/assets/stylesheets/srpm.scss @@ -0,0 +1,14 @@ +tr.arch { + & > td { + padding-top: 1em; + } + + td.package { + border-bottom: dotted 1px #aaa; + padding-right: 1em; + } + + td.size { + text-align: right; + } +} diff --git a/app/controllers/srpms_controller.rb b/app/controllers/srpms_controller.rb index bcb13806e..9ac1b1ecc 100644 --- a/app/controllers/srpms_controller.rb +++ b/app/controllers/srpms_controller.rb @@ -62,10 +62,7 @@ def get @srpm = @branch.srpms.where(name: params[:id]).includes(:branch).first! @mirrors = Mirror.where(branch_id: @branch).where("protocol != 'rsync'").order('mirrors.order_id ASC') @allsrpms = AllSrpmsWithName.new(params[:id]).search.decorate - @i586 = @srpm.packages.where(arch: 'i586').order('packages.name ASC') - @noarch = @srpm.packages.where(arch: 'noarch').order('packages.name ASC') - @x86_64 = @srpm.packages.where(arch: 'x86_64').order('packages.name ASC') - @arm = @srpm.packages.where(arch: 'arm').order('packages.name ASC') + @packages = @srpm.packages.order('packages.name ASC').group("packages.arch, packages.id").includes(:branch).decorate @all_bugs = AllBugsForSrpm.new(@srpm).decorate @opened_bugs = OpenedBugsForSrpm.new(@srpm).decorate end diff --git a/app/decorators/package_decorator.rb b/app/decorators/package_decorator.rb index a6b82c4c8..03d047af6 100644 --- a/app/decorators/package_decorator.rb +++ b/app/decorators/package_decorator.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class PackageDecorator < Draper::Decorator + include ActionView::Helpers::NumberHelper + delegate_all def as_json(*) @@ -27,4 +29,16 @@ def as_json(*) updated_at: updated_at.iso8601 } end + + def href + "http://ftp.altlinux.org/pub/distributions/ALTLinux#{path}" + end + + def human_size + number_to_human_size(size) + end + + def path + "#{branch.path}/files/#{arch}/RPMS/#{filename}" + end end diff --git a/app/decorators/packages_decorator.rb b/app/decorators/packages_decorator.rb new file mode 100644 index 000000000..167e62d07 --- /dev/null +++ b/app/decorators/packages_decorator.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class PackagesDecorator < Draper::CollectionDecorator + def arched_packages + self.group_by { |x| x.arch } + end +end diff --git a/app/lib/rpm/base.rb b/app/lib/rpm/base.rb index 0b163ffd6..9b35572dc 100644 --- a/app/lib/rpm/base.rb +++ b/app/lib/rpm/base.rb @@ -8,6 +8,10 @@ class Base attr_reader :file + def rpm + self.class + end + def initialize(file) @file = file end @@ -94,6 +98,14 @@ def md5 @md5 ||= Digest::MD5.file(file).hexdigest end + def has_valid_md5? + output = rpm.exec( + line: " -K #{rpm.no_signature_key} :file", + file: file) + + output && !(output.strip.split(': ').last.force_encoding('utf-8') !~ rpm.valid_signature_answer) + end + private def read_int(tag) @@ -106,21 +118,53 @@ def read_time(tag) end def read(tag) - output = read_raw(tag) - - output = nil if ['(none)', ''].include?(output) + output = rpm.exec( + line: '-qp --queryformat=:tag :file', + tag: tag, + file: file) output end - def read_raw(tag) - cocaine = Cocaine::CommandLine.new('rpm', '-qp --queryformat=:tag :file', environment: { 'LANG' => 'C' }) + class << self + def no_signature_key + @no_signature_key ||= exec('--nosignature').present? && '--nosignature' || '--nogpg' + end + + def use_common_signature? + no_signature_key == '--nosignature' + end + + def valid_signature_answer + use_common_signature? && /sha1 md5 O[KК]/ || /md5 O[KК]/ + end + + def hash_of args + if args.is_a?(String) + { line: args } + elsif args.is_a?(Hash) + args + else + raise + end + end + + def exec args + a_hash = hash_of(args) + + wrapper = Cocaine::CommandLine.new('rpm', a_hash[:line], environment: { 'LANG' => 'C' }) + + result = wrapper.run(a_hash) + result !~ /\A(\(none\)|)\z/ && result || nil + rescue Cocaine::CommandNotFoundError + Rails.logger.info('rpm command not found') + + nil + rescue Cocaine::ExitStatusError + Rails.logger.info('rpm exit status non zero') - cocaine.run(tag: tag, file: file) - rescue Cocaine::CommandNotFoundError - Rails.logger.info('rpm command not found') - rescue Cocaine::ExitStatusError - Rails.logger.info('rpm exit status non zero') + nil + end end - end + end end diff --git a/app/models/package.rb b/app/models/package.rb index 27d057f31..9977ae607 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -17,6 +17,8 @@ class Package < ApplicationRecord has_many :conflicts, dependent: :destroy + has_one :branch, through: :srpm + validates :groupname, presence: true validates :md5, presence: true diff --git a/app/models/rpm_check_md5.rb b/app/models/rpm_check_md5.rb index a25f6cb32..d399ecd15 100644 --- a/app/models/rpm_check_md5.rb +++ b/app/models/rpm_check_md5.rb @@ -2,11 +2,6 @@ class RPMCheckMD5 def self.check_md5(file) - output = `export LANG=C && rpm -K --nosignature #{ file }` - if !output.empty? && output.chop.split(': ').last == 'sha1 md5 OK' - true - else - false - end + RPM::Base.new(file).has_valid_md5? end end diff --git a/app/models/srpm.rb b/app/models/srpm.rb index f9b21b02c..d1a745b4c 100644 --- a/app/models/srpm.rb +++ b/app/models/srpm.rb @@ -44,6 +44,7 @@ class Srpm < ApplicationRecord validates :groupname, presence: true validates :md5, presence: true + validates_presence_of :buildtime # delegate :name, to: :branch, prefix: true diff --git a/app/views/shared/_arches.html.slim b/app/views/shared/_arches.html.slim new file mode 100644 index 000000000..b7f97fbaf --- /dev/null +++ b/app/views/shared/_arches.html.slim @@ -0,0 +1,13 @@ +- arches.each do |arch, packages| + tr.arch + td + b = "#{arch}: " + - packages.each.with_index do |package, index| + tr + td.package + b + = "· " + a.news.download { id="pack_#{index + 1}" href=package.href data={path: package.path} } = package.filename + = " (md5: #{package.md5})" + td.size + b = package.human_size diff --git a/app/views/srpms/get.html.erb b/app/views/srpms/get.html.erb index 127035dce..938a39d5a 100644 --- a/app/views/srpms/get.html.erb +++ b/app/views/srpms/get.html.erb @@ -38,59 +38,12 @@

 <%= link_to _('Main'), srpm_path(@srpm.branch, @srpm), class: 'news', title: _('information about SRPM') %>   <%= link_to _('Changelog'), changelog_srpm_path(@srpm.branch, @srpm), class: 'news', title: _('full changelog') %>   <%= link_to _('Spec'), spec_srpm_path(@srpm.branch, @srpm), class: 'news', title: _('spec') %>   <%= link_to _('Patches'), srpm_patches_path(@srpm.branch, @srpm), class: 'news', title: _('patches') %>   <%= link_to _('Sources'), srpm_sources_path(@srpm.branch, @srpm), class: 'news', title: _('sources') %>   <%= _('Download') %>   <%= link_to _('Gear'), gear_srpm_path(@srpm.branch, @srpm), class: 'news', title: _('this package in gear repositories') %>   <%= link_to _('Bugs and FR (%s/%s)') % [@opened_bugs.count, @all_bugs.count], bugs_srpm_path(@srpm), class: 'news', title: _('list of bugs and feature requests') %>   <%= link_to _('Repocop'), repocop_srpm_path(@srpm), class: 'news', title: _('repocop bugreports') %>  -

 <%= _('Choose a mirror:') %> - <% @mirrors.each do |mirror| %> - <%= "".html_safe %> + <%= "".html_safe %> <% end %>

@@ -100,9 +53,9 @@ function changeHref (val){ · <% if @branch.name == 'SisyphusARM' %> - <%= @srpm.filename %> (md5: <%= @srpm.md5 %>) + <%= @srpm.filename %> (md5: <%= @srpm.md5 %>) <% else %> - <%= @srpm.filename %> (md5: <%= @srpm.md5 %>) + <%= @srpm.filename %> (md5: <%= @srpm.md5 %>) <% end %> @@ -110,69 +63,7 @@ function changeHref (val){ -<% counter = 1 %> - -<% if @i586.count != 0 %> -
i586: - <% @i586.each do |i| %> - - · - - <%= i.filename %> - (md5: <%= i.md5 %>) - - <%= number_to_human_size(i.size) %> - - <% counter += 1 %> - <% end %> -<% end %> - -<% if @noarch.count != 0 %> -
noarch: - <% @noarch.each do |n| %> - - · - <% if @branch.name == 'SisyphusARM' %> - <%= n.filename %> - (md5: <%= n.md5 %>) - <% else %> - <%= n.filename %> - (md5: <%= n.md5 %>) - <% end %> - - <%= number_to_human_size(n.size) %> - - <% counter += 1 %> - <% end %> -<% end %> - -<% if @x86_64.count != 0 %> -
x86_64: - <% @x86_64.each do |x| %> - - · - <%= x.filename %> - (md5: <%= x.md5 %>) - - <%= number_to_human_size(x.size) %> - - <% counter += 1 %> - <% end %> -<% end %> - -<% if @arm.count != 0 %> -
arm: - <% @arm.each do |a| %> - - · - <%= a.filename %> - (md5: <%= a.md5 %>) - - <%= number_to_human_size(a.size) %> - - <% counter += 1 %> - <% end %> -<% end %> + <%= render partial: 'shared/arches', locals: { arches: @packages.arched_packages } %> diff --git a/config/application.rb b/config/application.rb index 4f2562b4a..94d87bb42 100644 --- a/config/application.rb +++ b/config/application.rb @@ -32,7 +32,6 @@ class Application < Rails::Application config.generators do |g| g.test_framework :rspec, fixture: true - g.fixture_replacement :factory_girl g.helper false end diff --git a/db/schema.rb b/db/schema.rb index 7b3c5377a..cb73e771c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,29 +10,44 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180418090153) do +ActiveRecord::Schema.define(version: 20180710172200) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + enable_extension "pg_stat_statements" + + create_table "branch_arches", force: :cascade do |t| + t.string "path" + t.string "arch" + t.string "kind" + t.boolean "active", default: false + t.bigint "branch_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["active"], name: "index_branch_arches_on_active" + t.index ["arch"], name: "index_branch_arches_on_arch" + t.index ["branch_id"], name: "index_branch_arches_on_branch_id" + t.index ["kind"], name: "index_branch_arches_on_kind" + end create_table "branches", id: :serial, force: :cascade do |t| - t.string "vendor" - t.string "name" + t.string "vendor", limit: 255 + t.string "name", limit: 255 t.datetime "created_at" t.datetime "updated_at" t.integer "order_id" - t.string "path" + t.string "path", limit: 255 end create_table "bugs", id: :serial, force: :cascade do |t| t.integer "bug_id" - t.string "bug_status" - t.string "resolution" - t.string "bug_severity" - t.string "product" - t.string "component" - t.string "assigned_to" - t.string "reporter" + t.string "bug_status", limit: 255 + t.string "resolution", limit: 255 + t.string "bug_severity", limit: 255 + t.string "product", limit: 255 + t.string "component", limit: 255 + t.string "assigned_to", limit: 255 + t.string "reporter", limit: 255 t.datetime "created_at" t.datetime "updated_at" t.text "short_desc" @@ -44,7 +59,7 @@ create_table "changelogs", id: :serial, force: :cascade do |t| t.integer "srpm_id" - t.string "changelogtime" + t.string "changelogtime", limit: 255 t.binary "changelogname" t.binary "changelogtext" t.datetime "created_at" @@ -55,9 +70,9 @@ create_table "conflicts", id: :serial, force: :cascade do |t| t.integer "package_id" - t.string "name" - t.string "version" - t.string "release" + t.string "name", limit: 255 + t.string "version", limit: 255 + t.string "release", limit: 255 t.datetime "created_at" t.datetime "updated_at" t.integer "flags" @@ -65,22 +80,36 @@ t.index ["package_id"], name: "index_conflicts_on_package_id" end + create_table "delayed_jobs", force: :cascade do |t| + t.integer "priority", default: 0 + t.integer "attempts", default: 0 + t.text "handler" + t.text "last_error" + t.datetime "run_at" + t.datetime "locked_at" + t.datetime "failed_at" + t.string "locked_by" + t.string "queue" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "freshmeats", id: :serial, force: :cascade do |t| - t.string "name" - t.string "version" - t.datetime "created_at" - t.datetime "updated_at" + t.string "name", limit: 255 + t.string "version", limit: 255 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "ftbfs", id: :serial, force: :cascade do |t| - t.string "name" - t.string "version" - t.string "release" + t.string "name", limit: 255 + t.string "version", limit: 255 + t.string "release", limit: 255 t.integer "weeks" t.integer "branch_id" t.datetime "created_at" t.datetime "updated_at" - t.string "arch" + t.string "arch", limit: 255 t.integer "maintainer_id" t.integer "epoch" t.index ["branch_id"], name: "index_ftbfs_on_branch_id" @@ -88,18 +117,18 @@ end create_table "gears", id: :serial, force: :cascade do |t| - t.string "repo" + t.string "repo", limit: 255 t.datetime "lastchange" t.datetime "created_at" t.datetime "updated_at" t.integer "maintainer_id" t.integer "srpm_id" - t.index ["maintainer_id"], name: "index_gears_on_maintainer_id" - t.index ["srpm_id"], name: "index_gears_on_srpm_id" + t.index ["maintainer_id"], name: "index_gitrepos_on_maintainer_id" + t.index ["srpm_id"], name: "index_gitrepos_on_srpm_id" end create_table "groups", id: :serial, force: :cascade do |t| - t.string "name" + t.string "name", limit: 255 t.datetime "created_at" t.datetime "updated_at" t.integer "branch_id" @@ -111,33 +140,33 @@ end create_table "maintainer_teams", id: :serial, force: :cascade do |t| - t.string "name", null: false - t.string "email", null: false - t.string "login", null: false - t.datetime "created_at" - t.datetime "updated_at" + t.string "name", limit: 255, null: false + t.string "email", limit: 255, null: false + t.string "login", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "maintainers", id: :serial, force: :cascade do |t| - t.string "name" - t.string "email" - t.string "login" + t.string "name", limit: 255 + t.string "email", limit: 255 + t.string "login", limit: 255 t.datetime "created_at" t.datetime "updated_at" - t.string "time_zone", default: "UTC" - t.string "jabber", default: "" + t.string "time_zone", limit: 255, default: "UTC" + t.string "jabber", limit: 255, default: "" t.text "info", default: "" - t.string "website", default: "" - t.string "location", default: "" + t.string "website", limit: 255, default: "" + t.string "location", limit: 255, default: "" end create_table "mirrors", id: :serial, force: :cascade do |t| t.integer "branch_id" t.integer "order_id" - t.string "name" - t.string "country" - t.string "uri" - t.string "protocol" + t.string "name", limit: 255 + t.string "country", limit: 255 + t.string "uri", limit: 255 + t.string "protocol", limit: 255 t.datetime "created_at" t.datetime "updated_at" t.index ["branch_id"], name: "index_mirrors_on_branch_id" @@ -145,9 +174,9 @@ create_table "obsoletes", id: :serial, force: :cascade do |t| t.integer "package_id" - t.string "name" - t.string "version" - t.string "release" + t.string "name", limit: 255 + t.string "version", limit: 255 + t.string "release", limit: 255 t.datetime "created_at" t.datetime "updated_at" t.integer "flags" @@ -156,23 +185,23 @@ end create_table "packages", id: :serial, force: :cascade do |t| - t.string "filename" - t.string "sourcepackage" - t.string "name" - t.string "version" - t.string "release" - t.string "arch" - t.string "summary" - t.string "license" - t.string "url" + t.string "filename", limit: 255 + t.string "sourcepackage", limit: 255 + t.string "name", limit: 255 + t.string "version", limit: 255 + t.string "release", limit: 255 + t.string "arch", limit: 255 + t.string "summary", limit: 255 + t.string "license", limit: 255 + t.string "url", limit: 255 t.text "description" t.datetime "buildtime" t.datetime "created_at" t.datetime "updated_at" t.integer "srpm_id" t.integer "group_id" - t.string "md5" - t.string "groupname" + t.string "md5", limit: 255 + t.string "groupname", limit: 255 t.integer "size" t.integer "epoch" t.index ["arch"], name: "index_packages_on_arch" @@ -187,15 +216,15 @@ t.binary "patch" t.datetime "created_at" t.datetime "updated_at" - t.string "filename" + t.string "filename", limit: 255 t.integer "size" t.index ["srpm_id"], name: "index_patches_on_srpm_id" end create_table "perl_watches", id: :serial, force: :cascade do |t| - t.string "name" - t.string "version" - t.string "path" + t.string "name", limit: 255 + t.string "version", limit: 255 + t.string "path", limit: 255 t.datetime "created_at" t.datetime "updated_at" t.index ["name"], name: "index_perl_watches_on_name" @@ -225,9 +254,9 @@ create_table "provides", id: :serial, force: :cascade do |t| t.integer "package_id" - t.string "name" - t.string "version" - t.string "release" + t.string "name", limit: 255 + t.string "version", limit: 255 + t.string "release", limit: 255 t.datetime "created_at" t.datetime "updated_at" t.integer "flags" @@ -236,24 +265,24 @@ end create_table "repocop_patches", id: :serial, force: :cascade do |t| - t.string "name" - t.string "version" - t.string "release" - t.string "url" + t.string "name", limit: 255 + t.string "version", limit: 255 + t.string "release", limit: 255 + t.string "url", limit: 255 t.integer "branch_id" t.index ["name"], name: "index_repocop_patches_on_name" end create_table "repocops", id: :serial, force: :cascade do |t| - t.string "name" - t.string "version" - t.string "release" - t.string "arch" - t.string "srcname" - t.string "srcversion" - t.string "srcrel" - t.string "testname" - t.string "status" + t.string "name", limit: 255 + t.string "version", limit: 255 + t.string "release", limit: 255 + t.string "arch", limit: 255 + t.string "srcname", limit: 255 + t.string "srcversion", limit: 255 + t.string "srcrel", limit: 255 + t.string "testname", limit: 255 + t.string "status", limit: 255 t.text "message" t.integer "branch_id" t.index ["srcname"], name: "index_repocops_on_srcname" @@ -263,9 +292,9 @@ create_table "requires", id: :serial, force: :cascade do |t| t.integer "package_id" - t.string "name" - t.string "version" - t.string "release" + t.string "name", limit: 255 + t.string "version", limit: 255 + t.string "release", limit: 255 t.datetime "created_at" t.datetime "updated_at" t.integer "flags" @@ -276,10 +305,10 @@ create_table "sources", id: :serial, force: :cascade do |t| t.integer "srpm_id" t.binary "content" - t.string "filename" + t.string "filename", limit: 255 t.integer "size" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "source" t.index ["srpm_id"], name: "index_sources_on_srpm_id" end @@ -293,28 +322,28 @@ end create_table "srpms", id: :serial, force: :cascade do |t| - t.string "filename" - t.string "name" - t.string "version" - t.string "release" - t.string "summary" - t.string "license" - t.string "url" + t.string "filename", limit: 255 + t.string "name", limit: 255 + t.string "version", limit: 255 + t.string "release", limit: 255 + t.string "summary", limit: 255 + t.string "license", limit: 255 + t.string "url", limit: 255 t.text "description" t.datetime "buildtime" t.datetime "created_at" t.datetime "updated_at" - t.string "repocop", default: "skip" + t.string "repocop", limit: 255, default: "skip" t.integer "branch_id" t.integer "group_id" - t.string "vendor" - t.string "distribution" - t.string "changelogname" + t.string "vendor", limit: 255 + t.string "distribution", limit: 255 + t.string "changelogname", limit: 255 t.text "changelogtext" - t.string "md5" + t.string "md5", limit: 255 t.boolean "delta", default: true, null: false t.integer "builder_id" - t.string "groupname" + t.string "groupname", limit: 255 t.integer "size" t.datetime "changelogtime" t.integer "epoch" @@ -326,7 +355,7 @@ end create_table "teams", id: :serial, force: :cascade do |t| - t.string "name" + t.string "name", limit: 255 t.boolean "leader" t.datetime "created_at" t.datetime "updated_at" @@ -337,27 +366,28 @@ end create_table "users", id: :serial, force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + t.string "email", limit: 255, default: "", null: false + t.string "encrypted_password", limit: 128, default: "", null: false + t.string "reset_password_token", limit: 255 t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", default: 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" + t.string "current_sign_in_ip", limit: 255 + t.string "last_sign_in_ip", limit: 255 + t.string "confirmation_token", limit: 255 t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.datetime "created_at" t.datetime "updated_at" - t.string "unconfirmed_email" + t.string "unconfirmed_email", limit: 255 t.boolean "admin", default: false t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + add_foreign_key "branch_arches", "branches", on_delete: :cascade add_foreign_key "srpms", "branches" end diff --git a/lib/tasks/sisyphus_aarch64.rake b/lib/tasks/sisyphus_aarch64.rake new file mode 100644 index 000000000..25460c2dc --- /dev/null +++ b/lib/tasks/sisyphus_aarch64.rake @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +namespace :update do + namespace :sisyphus do + desc 'Update Sisyphus stuff' + task aarch64: [:environment, :"update:lock"] do + puts "#{ Time.zone.now }: update *.aarch64.rpm from Sisyphus to database" + pathes = ['/ALT/Sisyphus/files/aarch64/RPMS/*.aarch64.rpm'] + branch = Branch.find_by!(name: 'Sisyphus') + Package.import_all(branch, pathes) + puts "#{ Time.zone.now }: end" + + puts "#{ Time.zone.now }: update acls in redis cache" + Acl.update_redis_cache(branch, 'http://git.altlinux.org/acl/list.packages.sisyphus') + puts "#{ Time.zone.now }: end" + + puts "#{ Time.zone.now }: update leaders in redis cache" + Leader.update_redis_cache(branch, 'http://git.altlinux.org/acl/list.packages.sisyphus') + puts "#{ Time.zone.now }: end" + + puts "#{ Time.zone.now }: update time" + Redis.current.set("#{ branch.name }:updated_at", Time.now.to_s) + puts "#{ Time.zone.now }: end" + Redis.current.del('__SYNC__') + end + end +end diff --git a/lib/tasks/update.rake b/lib/tasks/update.rake new file mode 100644 index 000000000..a47abb1ef --- /dev/null +++ b/lib/tasks/update.rake @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +namespace :update do + task lock: :environment do + if Redis.current.get('__SYNC__') + exist = begin + Process.kill(0, Redis.current.get('__SYNC__').to_i) + true + rescue + false + end + if exist + puts "#{ Time.zone.now }: update is locked by another cron script" + Process.exit!(true) + else + puts "#{ Time.zone.now }: dead lock found and deleted" + Redis.current.del('__SYNC__') + end + end + end +end diff --git a/spec/factories.rb b/spec/factories/maintainer_team_factory.rb similarity index 100% rename from spec/factories.rb rename to spec/factories/maintainer_team_factory.rb diff --git a/spec/factories/srpm_factory.rb b/spec/factories/srpm_factory.rb index 5d6455540..a7f67fbf2 100644 --- a/spec/factories/srpm_factory.rb +++ b/spec/factories/srpm_factory.rb @@ -4,11 +4,17 @@ factory :srpm do branch - name 'openbox' - version '3.4.11.1' - release 'alt1.1.1' + name { Faker::App.name.downcase } + version { Faker::App.semantic_version } + release { 'alt' + Faker::App.semantic_version } groupname 'Graphical desktop/Other' - filename 'openbox-3.4.11.1-alt1.1.1.src.rpm' - md5 'f87ff0eaa4e16b202539738483cd54d1' + filename { "#{@instance.name}-#{@instance.version}-#{@instance.release}.src.rpm" } + md5 { Digest::MD5.hexdigest(@instance.filename) } + + buildtime { Time.zone.now } + + after(:build) do |o| + o.group = create(:group, branch: o.branch) + end end end diff --git a/spec/models/rpm_check_md5_spec.rb b/spec/models/rpm_check_md5_spec.rb index d8922ba88..9ba295a97 100644 --- a/spec/models/rpm_check_md5_spec.rb +++ b/spec/models/rpm_check_md5_spec.rb @@ -3,15 +3,19 @@ require 'rails_helper' describe RPMCheckMD5 do + let(:valid_file) { './spec/data/catpkt-1.0-alt5.src.rpm' } + let(:non_exist_file) { './spec/data/invalid-0.0-alt0.src.rpm' } + let(:broken_file) { './spec/data/broken-1.0-alt5.src.rpm' } + it 'should verify md5 sum of srpm before import and return true for good srpm' do - file = 'openbox-3.4.11.1-alt1.1.1.src.rpm' - expect(RPMCheckMD5).to receive(:`).with("export LANG=C && rpm -K --nogpg #{ file }").and_return("openbox-3.5.0-alt1.src.rpm: md5 OK\n") - expect(RPMCheckMD5.check_md5(file)).to eq(true) + expect(RPMCheckMD5.check_md5(valid_file)).to be_truthy + end + + it 'should verify md5 sum of srpm before import and return false for non exist srpm' do + expect(RPMCheckMD5.check_md5(non_exist_file)).to be_falsey end it 'should verify md5 sum of srpm before import and return false for broken srpm' do - file = 'openbox-3.4.11.1-alt1.1.1.src.rpm' - expect(RPMCheckMD5).to receive(:`).with("export LANG=C && rpm -K --nogpg #{ file }").and_return('') - expect(RPMCheckMD5.check_md5(file)).to eq(false) + expect(RPMCheckMD5.check_md5(broken_file)).to be_falsey end end diff --git a/vendor/cache/slim-3.0.9.gem b/vendor/cache/slim-3.0.9.gem new file mode 100644 index 000000000..508f8e36c Binary files /dev/null and b/vendor/cache/slim-3.0.9.gem differ diff --git a/vendor/cache/temple-0.8.0.gem b/vendor/cache/temple-0.8.0.gem new file mode 100644 index 000000000..19c96cfd9 Binary files /dev/null and b/vendor/cache/temple-0.8.0.gem differ