Skip to content
This repository was archived by the owner on Nov 19, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.1
ext-ruby-2.5.1
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ gem 'browser'
gem 'http_accept_language'
# gem 'molinillo', require: false

# view
gem 'slim'

group :production, :development do
gem 'redis'
end
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -514,6 +518,7 @@ DEPENDENCIES
sidekiq
simplecov
sitemap_generator
slim
spring
spring-commands-rspec
spring-commands-rubocop
Expand Down
17 changes: 17 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
2 changes: 2 additions & 0 deletions app/assets/javascripts/br/local.js.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
$(document).ready(function() {
$('#topMain').toggle(function() {
$('#topMain').attr("src", "<%= asset_path 'restore.gif' %>");
Expand Down Expand Up @@ -39,3 +40,4 @@ $(document).ready(function() {
$('#topBranchesDiv').show();
});
});
*/
2 changes: 2 additions & 0 deletions app/assets/javascripts/en/local.js.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
$(document).ready(function() {
$('#topMain').toggle(function() {
$('#topMain').attr("src", "<%= asset_path 'restore.gif' %>");
Expand Down Expand Up @@ -39,3 +40,4 @@ $(document).ready(function() {
$('#topBranchesDiv').show();
});
});
*/
2 changes: 2 additions & 0 deletions app/assets/javascripts/ru/local.js.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
$(document).ready(function() {
$('#topMain').toggle(function() {
$('#topMain').attr("src", "<%= asset_path 'restore.gif' %>");
Expand Down Expand Up @@ -39,3 +40,4 @@ $(document).ready(function() {
$('#topBranchesDiv').show();
});
});
*/
2 changes: 2 additions & 0 deletions app/assets/javascripts/uk/local.js.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
$(document).ready(function() {
$('#topMain').toggle(function() {
$('#topMain').attr("src", "<%= asset_path 'restore.gif' %>");
Expand Down Expand Up @@ -39,3 +40,4 @@ $(document).ready(function() {
$('#topBranchesDiv').show();
});
});
*/
14 changes: 14 additions & 0 deletions app/assets/stylesheets/srpm.scss
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 1 addition & 4 deletions app/controllers/srpms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions app/decorators/package_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class PackageDecorator < Draper::Decorator
include ActionView::Helpers::NumberHelper

delegate_all

def as_json(*)
Expand All @@ -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
7 changes: 7 additions & 0 deletions app/decorators/packages_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class PackagesDecorator < Draper::CollectionDecorator
def arched_packages
self.group_by { |x| x.arch }
end
end
66 changes: 55 additions & 11 deletions app/lib/rpm/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class Base

attr_reader :file

def rpm
self.class
end

def initialize(file)
@file = file
end
Expand Down Expand Up @@ -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)
Expand All @@ -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
2 changes: 2 additions & 0 deletions app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions app/models/rpm_check_md5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions app/models/srpm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions app/views/shared/_arches.html.slim
Original file line number Diff line number Diff line change
@@ -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
Loading