From dbf3f24b21ae66c0a835f2ced06edcafa0b8267f Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 14 Nov 2013 02:01:12 +0400 Subject: [PATCH 01/17] #321: added UI for mass_import --- .../projects/projects_controller.rb | 27 +++++++++++++++++-- app/models/project.rb | 20 ++++++++++++-- .../projects/projects/_filters.html.haml | 3 +++ app/views/projects/projects/_form.html.haml | 14 +--------- app/views/projects/projects/_owner.html.haml | 12 +++++++++ .../projects/projects/mass_import.html.haml | 24 +++++++++++++++++ config/locales/models/project.en.yml | 3 +++ config/locales/models/project.ru.yml | 3 +++ config/routes.rb | 7 ++++- 9 files changed, 95 insertions(+), 18 deletions(-) create mode 100644 app/views/projects/projects/_owner.html.haml create mode 100644 app/views/projects/projects/mass_import.html.haml diff --git a/app/controllers/projects/projects_controller.rb b/app/controllers/projects/projects_controller.rb index 03d14cdc3..c91e70e24 100644 --- a/app/controllers/projects/projects_controller.rb +++ b/app/controllers/projects/projects_controller.rb @@ -3,6 +3,7 @@ class Projects::ProjectsController < Projects::BaseController include ProjectsHelper before_filter :authenticate_user! load_and_authorize_resource :id_param => :project_name # to force member actions load + before_filter :who_owns, :only => [:new, :create, :mass_import, :run_mass_import] def index @projects = Project.accessible_by(current_ability, :membered) @@ -24,7 +25,26 @@ class Projects::ProjectsController < Projects::BaseController def new @project = Project.new - @who_owns = :me + end + + def mass_import + @project = Project.new(:mass_import => true) + end + + def run_mass_import + @project = Project.new params[:project] + @project.owner = choose_owner + authorize! :write, @project.owner if @project.owner.class == Group + @project.valid? + @project.errors.messages.slice! :url + if @project.errors.messages.blank? # We need only url validation + @project.mass_import + flash[:notice] = t('flash.project.mass_import_added_to_queue') + redirect_to projects_path + else + flash[:warning] = @project.errors.full_messages.join('. ') + render :mass_import + end end def edit @@ -33,7 +53,6 @@ class Projects::ProjectsController < Projects::BaseController def create @project = Project.new params[:project] @project.owner = choose_owner - @who_owns = (@project.owner_type == 'User' ? :me : :group) authorize! :write, @project.owner if @project.owner.class == Group if @project.save @@ -115,6 +134,10 @@ class Projects::ProjectsController < Projects::BaseController protected + def who_owns + @who_owns = (@project.try(:owner_type) == 'User' ? :me : :group) + end + def prepare_list(projects, groups, owners) res = {} diff --git a/app/models/project.rb b/app/models/project.rb index b7dbd8e53..38e01e228 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -29,8 +29,10 @@ class Project < ActiveRecord::Base validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, - :format => {:with => /\A#{NAME_REGEXP}\z/, :message => I18n.t("activerecord.errors.project.uname")} + :format => {:with => /\A#{NAME_REGEXP}\z/, + :message => I18n.t("activerecord.errors.project.uname")} validates :maintainer_id, :presence => true, :unless => :new_record? + validates :url, :presence => true, :format => {:with => /\Ahttps?:\/\/[\S]+\z/}, :if => :mass_import validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES} validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS } validate :check_default_branch @@ -43,7 +45,9 @@ class Project < ActiveRecord::Base errors.delete :project_to_repositories end - attr_accessible :name, :description, :visibility, :srpm, :is_package, :default_branch, :has_issues, :has_wiki, :maintainer_id, :publish_i686_into_x86_64 + attr_accessible :name, :description, :visibility, :srpm, :is_package, :default_branch, + :has_issues, :has_wiki, :maintainer_id, :publish_i686_into_x86_64, + :url, :srpms_list, :mass_import attr_readonly :owner_id, :owner_type scope :recent, order("lower(#{table_name}.name) ASC") @@ -82,6 +86,8 @@ class Project < ActiveRecord::Base has_ancestry :orphan_strategy => :rootify #:adopt not available yet + attr_accessor :url, :srpms_list, :mass_import + include Modules::Models::Owner include Modules::Models::Git include Modules::Models::Wiki @@ -96,6 +102,16 @@ class Project < ActiveRecord::Base def find_by_owner_and_name!(owner_name, project_name) find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound end + + def self.run_mass_import(url, srpms_list, visibility, owner) + + + + end + end + + def mass_import + Project.perform_later :clone_build, :run_mass_import, url, srpms_list, visibility, owner end def name_with_owner diff --git a/app/views/projects/projects/_filters.html.haml b/app/views/projects/projects/_filters.html.haml index 12577ac68..bf4da5021 100644 --- a/app/views/projects/projects/_filters.html.haml +++ b/app/views/projects/projects/_filters.html.haml @@ -6,6 +6,9 @@ - if can?(:create, Project) .bordered.bpadding20 = link_to t('layout.projects.new'), new_project_path, :class => 'button' + .both + %br + = link_to t('layout.projects.mass_import'), mass_import_projects_path, :class => 'button' .bordered.bpadding20 %h3=t('layout.relations.filters') - options_for_filters(@all_projects, @groups, @owners).each do |options| diff --git a/app/views/projects/projects/_form.html.haml b/app/views/projects/projects/_form.html.haml index c009d642f..04b3f4cb9 100644 --- a/app/views/projects/projects/_form.html.haml +++ b/app/views/projects/projects/_form.html.haml @@ -7,22 +7,10 @@ .rightlist= f.text_area :description, :class => 'text_field', :cols => 80 .both - if [:new, :create].include? act - .leftlist= f.label :owner - .rightlist - = label_tag t("activerecord.attributes.project.who_owns.me") - - if Group.can_own_project(current_user).count > 0 - = radio_button_tag :who_owns, 'me', @who_owns == :me #{}.merge( (@who_owns == :me) ? {:checked => 'checked'} : {} ) - = label_tag t("activerecord.attributes.project.who_owns.group") - = radio_button_tag :who_owns, 'group', @who_owns == :group #{}.merge( (@who_owns == :group) ? {:checked => 'checked'} : {} ) - -# TODO: Make our own select_box helper with new design, blackjack and bitches! - = select_tag :owner_id, options_from_collection_for_select( Group.can_own_project(current_user), :id, :name ) - - else - = hidden_field_tag :who_owns, :me - .both + = render 'owner', :f => f .leftlist= f.label :visibility .rightlist - =# f.select :visibility, Project::VISIBILITIES - Project::VISIBILITIES.each do |visibility| = f.radio_button :visibility, visibility, :class => 'niceRadio' - if visibility == 'open' diff --git a/app/views/projects/projects/_owner.html.haml b/app/views/projects/projects/_owner.html.haml new file mode 100644 index 000000000..3d1d19653 --- /dev/null +++ b/app/views/projects/projects/_owner.html.haml @@ -0,0 +1,12 @@ +.leftlist= f.label :owner +.rightlist + = label_tag t("activerecord.attributes.project.who_owns.me") + - if Group.can_own_project(current_user).count > 0 + = radio_button_tag :who_owns, 'me', @who_owns == :me #{}.merge( (@who_owns == :me) ? {:checked => 'checked'} : {} ) + = label_tag t("activerecord.attributes.project.who_owns.group") + = radio_button_tag :who_owns, 'group', @who_owns == :group #{}.merge( (@who_owns == :group) ? {:checked => 'checked'} : {} ) + -# TODO: Make our own select_box helper with new design, blackjack and bitches! + = select_tag :owner_id, options_from_collection_for_select( Group.can_own_project(current_user), :id, :name ) + - else + = hidden_field_tag :who_owns, :me +.both \ No newline at end of file diff --git a/app/views/projects/projects/mass_import.html.haml b/app/views/projects/projects/mass_import.html.haml new file mode 100644 index 000000000..d2cb71eef --- /dev/null +++ b/app/views/projects/projects/mass_import.html.haml @@ -0,0 +1,24 @@ +%h3.bpadding10= title t("layout.projects.mass_import") += form_for @project, :url => run_mass_import_projects_path, :html => { :class => :form } do |f| + = f.hidden_field :mass_import + .leftlist= f.label :url + .rightlist= f.text_field :url + .both + .leftlist= f.label :srpms_list + .rightlist= f.text_area :srpms_list + .both + = render 'owner', :f => f + + .leftlist= f.label :visibility + .rightlist + - Project::VISIBILITIES.each do |visibility| + = f.radio_button :visibility, visibility, :class => 'niceRadio' + - if visibility == 'open' + = image_tag("unlock.png") + - else + = image_tag("lock.png") + = t("activerecord.attributes.project.visibilities.#{visibility}") + .both + .hr + .button_block + = f.submit t('layout.add'), :data => {'disable-with' => t('layout.saving')} \ No newline at end of file diff --git a/config/locales/models/project.en.yml b/config/locales/models/project.en.yml index d616729d1..f3d167d41 100644 --- a/config/locales/models/project.en.yml +++ b/config/locales/models/project.en.yml @@ -1,6 +1,7 @@ en: layout: projects: + mass_import: Mass import branches: Branches delete_branch: Delete branch restore_branch: Restore branch @@ -89,6 +90,8 @@ en: project: Project attributes: project: + url: URL + srpms_list: SRPMs list name: Name description: Descripton owner: Owner diff --git a/config/locales/models/project.ru.yml b/config/locales/models/project.ru.yml index 5360e237c..a6bfcc257 100644 --- a/config/locales/models/project.ru.yml +++ b/config/locales/models/project.ru.yml @@ -1,6 +1,7 @@ ru: layout: projects: + mass_import: Массовый импорт branches: Ветки delete_branch: Удалить ветку restore_branch: Восстановить ветку @@ -89,6 +90,8 @@ ru: project: Проект attributes: project: + url: URL + srpms_list: Список SRPMs name: Название description: Описание owner: Владелец diff --git a/config/routes.rb b/config/routes.rb index d8e93236f..4379aad25 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -284,7 +284,12 @@ Rosa::Application.routes.draw do end end - resources :projects, :only => [:index, :new, :create] + resources :projects, :only => [:index, :new, :create] do + collection do + post :run_mass_import + get :mass_import + end + end scope ':owner_name/:project_name', :constraints => {:project_name => Project::NAME_REGEXP} do # project scope :as => 'project' do resources :wiki do From 7f3ecbfdc7d9b2f40b4cf04cad6a7900658ce378 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Nov 2013 00:23:22 +0400 Subject: [PATCH 02/17] #321: updated #run_mass_import method --- app/models/project.rb | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 38e01e228..a05a67c86 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,7 +1,11 @@ # -*- encoding : utf-8 -*- +require 'nokogiri' +require 'open-uri' + class Project < ActiveRecord::Base VISIBILITIES = ['open', 'hidden'] MAX_OWN_PROJECTS = 32000 + MAX_SRC_SIZE = 1024*1024*256 NAME_REGEXP = /[\w\-\+\.]+/ belongs_to :owner, :polymorphic => true, :counter_cache => :own_projects_count @@ -104,10 +108,46 @@ class Project < ActiveRecord::Base end def self.run_mass_import(url, srpms_list, visibility, owner) - + doc = Nokogiri::HTML(open(url)) + links = doc.css("a[href$='.src.rpm']") + return if links.count == 0 + filter = srpms_list.lines.map(&:chomp).map(&:strip).select(&:present?) + dir = Dir.mktmpdir('mass-import-', '/tmp') + links.each do |link| + begin + package = link.attributes['href'].value + package.chomp!; package.strip! + next if package.size == 0 || package !~ /^[\w\.\-]+$/ + + uri = URI "#{url}/#{package}" + srpm_file = "#{dir}/#{package}" + Net::HTTP.start(uri.host) do |http| + if http.request_head(uri.path)['content-length'].to_i < MAX_SRC_SIZE + f = open(srpm_file) + http.request_get(uri.path) do |resp| + resp.read_body{ |segment| f.write(segment) } + end + f.close + end + end + if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? + project = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id) + repo.projects << project rescue nil + description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`) + project.update_attributes(:visibility => visibility, :description => description) + project.import_srpm(srpm_file, owner.own_platforms.name) + end + File.delete srpm_file + rescue => e + f.close if f + Airbrake.notify_or_ignore(e, :link => link.to_s) + end + end + FileUtils.remove_entry_secure dir end + end def mass_import From e538a3d5a668fdc9eebd2e480caca2f95b05aaa3 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Nov 2013 01:26:05 +0400 Subject: [PATCH 03/17] #321: added debug info, some fixes --- .../projects/projects_controller.rb | 2 +- app/models/project.rb | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/controllers/projects/projects_controller.rb b/app/controllers/projects/projects_controller.rb index c91e70e24..7c4e735e4 100644 --- a/app/controllers/projects/projects_controller.rb +++ b/app/controllers/projects/projects_controller.rb @@ -38,7 +38,7 @@ class Projects::ProjectsController < Projects::BaseController @project.valid? @project.errors.messages.slice! :url if @project.errors.messages.blank? # We need only url validation - @project.mass_import + @project.init_mass_import flash[:notice] = t('flash.project.mass_import_added_to_queue') redirect_to projects_path else diff --git a/app/models/project.rb b/app/models/project.rb index a05a67c86..f62536b27 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,6 +1,7 @@ # -*- encoding : utf-8 -*- require 'nokogiri' require 'open-uri' +require 'iconv' class Project < ActiveRecord::Base VISIBILITIES = ['open', 'hidden'] @@ -107,25 +108,29 @@ class Project < ActiveRecord::Base find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound end - def self.run_mass_import(url, srpms_list, visibility, owner) + def run_mass_import(url, srpms_list, visibility, owner) doc = Nokogiri::HTML(open(url)) links = doc.css("a[href$='.src.rpm']") return if links.count == 0 filter = srpms_list.lines.map(&:chomp).map(&:strip).select(&:present?) + platform = owner.own_platforms.first + repository = platform.repositories.first dir = Dir.mktmpdir('mass-import-', '/tmp') links.each do |link| begin package = link.attributes['href'].value package.chomp!; package.strip! + + Rails.logger.debug "[Project#run_mass_import] package: #{package}" next if package.size == 0 || package !~ /^[\w\.\-]+$/ uri = URI "#{url}/#{package}" srpm_file = "#{dir}/#{package}" Net::HTTP.start(uri.host) do |http| if http.request_head(uri.path)['content-length'].to_i < MAX_SRC_SIZE - f = open(srpm_file) + f = open(srpm_file, 'wb') http.request_get(uri.path) do |resp| resp.read_body{ |segment| f.write(segment) } end @@ -133,15 +138,22 @@ class Project < ActiveRecord::Base end end if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? + Rails.logger.debug "[Project#run_mass_import] Import '#{name}'..." project = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id) - repo.projects << project rescue nil description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`) project.update_attributes(:visibility => visibility, :description => description) - project.import_srpm(srpm_file, owner.own_platforms.name) + repository.projects << project rescue nil + if project.valid? + project.import_srpm srpm_file + Rails.logger.debug "[Project#run_mass_import] Code import complete!" + else + Rails.logger.debug "[Project#run_mass_import] Can't find or create project: #{project.errors.full_messages.join('. ')}" + end end File.delete srpm_file rescue => e - f.close if f + f.close if defined?(f) + Rails.logger.error e Airbrake.notify_or_ignore(e, :link => link.to_s) end end @@ -150,7 +162,7 @@ class Project < ActiveRecord::Base end - def mass_import + def init_mass_import Project.perform_later :clone_build, :run_mass_import, url, srpms_list, visibility, owner end From d2cfb0af812a659a084ee593d285cbe6e606f741 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Nov 2013 01:34:34 +0400 Subject: [PATCH 04/17] #321: updated access rights --- app/models/ability.rb | 1 + app/views/projects/projects/_filters.html.haml | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 518bd556c..092d78de8 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -60,6 +60,7 @@ class Ability can :remove_user, Group can :create, Project + can([:mass_import, :run_mass_import], Project) { user.platforms.select(&:main?).find{ |p| local_admin?(p) } } can :read, Project, :visibility => 'open' can [:read, :archive, :membered, :get_id], Project, :owner_type => 'User', :owner_id => user.id can [:read, :archive, :membered, :get_id], Project, :owner_type => 'Group', :owner_id => user.group_ids diff --git a/app/views/projects/projects/_filters.html.haml b/app/views/projects/projects/_filters.html.haml index bf4da5021..6b578a3b1 100644 --- a/app/views/projects/projects/_filters.html.haml +++ b/app/views/projects/projects/_filters.html.haml @@ -6,9 +6,10 @@ - if can?(:create, Project) .bordered.bpadding20 = link_to t('layout.projects.new'), new_project_path, :class => 'button' - .both - %br - = link_to t('layout.projects.mass_import'), mass_import_projects_path, :class => 'button' + - if can?(:mass_import, Project) + .both + %br + = link_to t('layout.projects.mass_import'), mass_import_projects_path, :class => 'button' .bordered.bpadding20 %h3=t('layout.relations.filters') - options_for_filters(@all_projects, @groups, @owners).each do |options| From d1cf100082e634c8a10659e4914f2b4c755c99f3 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Nov 2013 01:42:03 +0400 Subject: [PATCH 05/17] #321: Fixed access rights --- app/models/ability.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 092d78de8..01baddc0c 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -60,7 +60,7 @@ class Ability can :remove_user, Group can :create, Project - can([:mass_import, :run_mass_import], Project) { user.platforms.select(&:main?).find{ |p| local_admin?(p) } } + can([:mass_import, :run_mass_import], Project) if user.platforms.select(&:main?).find{ |p| local_admin?(p) }.present? can :read, Project, :visibility => 'open' can [:read, :archive, :membered, :get_id], Project, :owner_type => 'User', :owner_id => user.id can [:read, :archive, :membered, :get_id], Project, :owner_type => 'Group', :owner_id => user.group_ids From 19ff6288ce36b084c40003dd4d982dd056ffdea1 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Nov 2013 18:46:09 +0400 Subject: [PATCH 06/17] #321: added select_tag with repositories into Mass Import --- .../projects/projects_controller.rb | 1 + app/helpers/projects_helper.rb | 9 +++++++ app/models/project.rb | 27 +++++++++++-------- .../projects/projects/mass_import.html.haml | 3 +++ config/locales/models/project.en.yml | 1 + config/locales/models/project.ru.yml | 1 + 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/app/controllers/projects/projects_controller.rb b/app/controllers/projects/projects_controller.rb index 7c4e735e4..920fa2afa 100644 --- a/app/controllers/projects/projects_controller.rb +++ b/app/controllers/projects/projects_controller.rb @@ -35,6 +35,7 @@ class Projects::ProjectsController < Projects::BaseController @project = Project.new params[:project] @project.owner = choose_owner authorize! :write, @project.owner if @project.owner.class == Group + authorize! :add_project, Repository.find(params[:project][:add_to_repository_id]) @project.valid? @project.errors.messages.slice! :url if @project.errors.messages.blank? # We need only url validation diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 1c837c144..8e1cd9082 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -20,6 +20,15 @@ module ProjectsHelper end.sort_by{ |f| f[:uname] } end + def repositories_grouped_by_platform + groups = {} + Platform.accessible_by(current_ability, :related).order(:name).each do |platform| + next unless can?(:local_admin_manage, platform) + groups[platform.name] = Repository.custom_sort(platform.repositories).map{ |r| [r.name, r.id] } + end + groups + end + def git_repo_url(name) if current_user "#{request.protocol}#{current_user.uname}@#{request.host_with_port}/#{name}.git" diff --git a/app/models/project.rb b/app/models/project.rb index f62536b27..538380e5b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -38,6 +38,7 @@ class Project < ActiveRecord::Base :message => I18n.t("activerecord.errors.project.uname")} validates :maintainer_id, :presence => true, :unless => :new_record? validates :url, :presence => true, :format => {:with => /\Ahttps?:\/\/[\S]+\z/}, :if => :mass_import + validates :add_to_repository_id, :presence => true, :if => :mass_import validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES} validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS } validate :check_default_branch @@ -52,7 +53,7 @@ class Project < ActiveRecord::Base attr_accessible :name, :description, :visibility, :srpm, :is_package, :default_branch, :has_issues, :has_wiki, :maintainer_id, :publish_i686_into_x86_64, - :url, :srpms_list, :mass_import + :url, :srpms_list, :mass_import, :add_to_repository_id attr_readonly :owner_id, :owner_type scope :recent, order("lower(#{table_name}.name) ASC") @@ -91,7 +92,7 @@ class Project < ActiveRecord::Base has_ancestry :orphan_strategy => :rootify #:adopt not available yet - attr_accessor :url, :srpms_list, :mass_import + attr_accessor :url, :srpms_list, :mass_import, :add_to_repository_id include Modules::Models::Owner include Modules::Models::Git @@ -108,15 +109,14 @@ class Project < ActiveRecord::Base find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound end - def run_mass_import(url, srpms_list, visibility, owner) + def run_mass_import(url, srpms_list, visibility, owner, add_to_repository_id) doc = Nokogiri::HTML(open(url)) links = doc.css("a[href$='.src.rpm']") return if links.count == 0 filter = srpms_list.lines.map(&:chomp).map(&:strip).select(&:present?) - - platform = owner.own_platforms.first - repository = platform.repositories.first + repository = Repository.find add_to_repository_id + platform = repository.platform dir = Dir.mktmpdir('mass-import-', '/tmp') links.each do |link| begin @@ -139,22 +139,27 @@ class Project < ActiveRecord::Base end if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? Rails.logger.debug "[Project#run_mass_import] Import '#{name}'..." - project = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id) + next if owner.projects.exists?(:name => name) || (filter.present? && !filter.include?(name)) description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`) - project.update_attributes(:visibility => visibility, :description => description) + project = owner.projects.create( + :name => name, + :description => description, + :visibility => visibility + ) repository.projects << project rescue nil if project.valid? - project.import_srpm srpm_file + project.import_srpm srpm_file, platform.name Rails.logger.debug "[Project#run_mass_import] Code import complete!" else Rails.logger.debug "[Project#run_mass_import] Can't find or create project: #{project.errors.full_messages.join('. ')}" end end - File.delete srpm_file rescue => e f.close if defined?(f) Rails.logger.error e Airbrake.notify_or_ignore(e, :link => link.to_s) + ensure + File.delete srpm_file if defined?(srpm_file) end end FileUtils.remove_entry_secure dir @@ -163,7 +168,7 @@ class Project < ActiveRecord::Base end def init_mass_import - Project.perform_later :clone_build, :run_mass_import, url, srpms_list, visibility, owner + Project.perform_later :clone_build, :run_mass_import, url, srpms_list, visibility, owner, add_to_repository_id end def name_with_owner diff --git a/app/views/projects/projects/mass_import.html.haml b/app/views/projects/projects/mass_import.html.haml index d2cb71eef..796ca274a 100644 --- a/app/views/projects/projects/mass_import.html.haml +++ b/app/views/projects/projects/mass_import.html.haml @@ -7,6 +7,9 @@ .leftlist= f.label :srpms_list .rightlist= f.text_area :srpms_list .both + .leftlist= f.label :add_to_repository_id + .rightlist= f.select :add_to_repository_id, repositories_grouped_by_platform + .both = render 'owner', :f => f .leftlist= f.label :visibility diff --git a/config/locales/models/project.en.yml b/config/locales/models/project.en.yml index f3d167d41..8d5e310e6 100644 --- a/config/locales/models/project.en.yml +++ b/config/locales/models/project.en.yml @@ -91,6 +91,7 @@ en: attributes: project: url: URL + add_to_repository_id: Add to repository srpms_list: SRPMs list name: Name description: Descripton diff --git a/config/locales/models/project.ru.yml b/config/locales/models/project.ru.yml index a6bfcc257..1896ff2b1 100644 --- a/config/locales/models/project.ru.yml +++ b/config/locales/models/project.ru.yml @@ -91,6 +91,7 @@ ru: attributes: project: url: URL + add_to_repository_id: Добавить в репозиторий srpms_list: Список SRPMs name: Название description: Описание From a79cb92abf0a8b469cefc8a81cfb7cf0eb5b026d Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Nov 2013 19:12:02 +0400 Subject: [PATCH 07/17] #321: fixed: undefined method projects for nil:NilClass --- app/models/project.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 538380e5b..7885ced05 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -141,13 +141,14 @@ class Project < ActiveRecord::Base Rails.logger.debug "[Project#run_mass_import] Import '#{name}'..." next if owner.projects.exists?(:name => name) || (filter.present? && !filter.include?(name)) description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`) - project = owner.projects.create( + project = owner.projects.build( :name => name, :description => description, :visibility => visibility ) - repository.projects << project rescue nil - if project.valid? + project.owner = owner + if project.save + repository.projects << project rescue nil project.import_srpm srpm_file, platform.name Rails.logger.debug "[Project#run_mass_import] Code import complete!" else From 1742a7357db9bd7024aef35a9ae1d3ced2f27ccf Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Nov 2013 20:25:36 +0400 Subject: [PATCH 08/17] #321: Fixed: translation missing --- app/models/project.rb | 4 +++- config/locales/models/project.en.yml | 1 + config/locales/models/project.ru.yml | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 7885ced05..438562108 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -144,11 +144,13 @@ class Project < ActiveRecord::Base project = owner.projects.build( :name => name, :description => description, - :visibility => visibility + :visibility => visibility, + :is_package => false # See: Hook for #attach_to_personal_repository ) project.owner = owner if project.save repository.projects << project rescue nil + project.update_attributes(:is_package => true) project.import_srpm srpm_file, platform.name Rails.logger.debug "[Project#run_mass_import] Code import complete!" else diff --git a/config/locales/models/project.en.yml b/config/locales/models/project.en.yml index 8d5e310e6..586f0c5fb 100644 --- a/config/locales/models/project.en.yml +++ b/config/locales/models/project.en.yml @@ -77,6 +77,7 @@ en: flash: project: + mass_import_added_to_queue: Mass import added to queue saved: Project saved save_error: Unable to save project save_warning_ssh_key: Project owner must provide a SSH key in his profile diff --git a/config/locales/models/project.ru.yml b/config/locales/models/project.ru.yml index 1896ff2b1..12821d64c 100644 --- a/config/locales/models/project.ru.yml +++ b/config/locales/models/project.ru.yml @@ -77,6 +77,7 @@ ru: flash: project: + mass_import_added_to_queue: Массовый импорт добавлен в очередь saved: Проект успешно сохранен save_error: Не удалось сохранить проект save_warning_ssh_key: Владельцу проекта необходимо указать в профиле свой SSH ключ From 51e7ed426f9f923a2a76e33465ba957edc91d4d4 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Nov 2013 20:30:36 +0400 Subject: [PATCH 09/17] #321: remove tmp folder in ensure block --- app/models/project.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 438562108..d52c84862 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -165,7 +165,8 @@ class Project < ActiveRecord::Base File.delete srpm_file if defined?(srpm_file) end end - FileUtils.remove_entry_secure dir + ensure + FileUtils.remove_entry_secure dir if if defined?(dir) end end From 65cfed25aba9fad600c1de87765b61270684601d Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Nov 2013 20:32:50 +0400 Subject: [PATCH 10/17] #321: misprint --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index d52c84862..86ffc7087 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -166,7 +166,7 @@ class Project < ActiveRecord::Base end end ensure - FileUtils.remove_entry_secure dir if if defined?(dir) + FileUtils.remove_entry_secure dir if defined?(dir) end end From b0d691f7243943dda24c845ac2553c1d1f5149b9 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Nov 2013 21:09:55 +0400 Subject: [PATCH 11/17] #321: remove unnecessary code --- app/models/project.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 86ffc7087..86c10b35a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -123,7 +123,6 @@ class Project < ActiveRecord::Base package = link.attributes['href'].value package.chomp!; package.strip! - Rails.logger.debug "[Project#run_mass_import] package: #{package}" next if package.size == 0 || package !~ /^[\w\.\-]+$/ uri = URI "#{url}/#{package}" @@ -138,7 +137,6 @@ class Project < ActiveRecord::Base end end if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? - Rails.logger.debug "[Project#run_mass_import] Import '#{name}'..." next if owner.projects.exists?(:name => name) || (filter.present? && !filter.include?(name)) description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`) project = owner.projects.build( @@ -152,15 +150,11 @@ class Project < ActiveRecord::Base repository.projects << project rescue nil project.update_attributes(:is_package => true) project.import_srpm srpm_file, platform.name - Rails.logger.debug "[Project#run_mass_import] Code import complete!" - else - Rails.logger.debug "[Project#run_mass_import] Can't find or create project: #{project.errors.full_messages.join('. ')}" end end rescue => e f.close if defined?(f) - Rails.logger.error e - Airbrake.notify_or_ignore(e, :link => link.to_s) + Airbrake.notify_or_ignore(e, :link => link.to_s, :url => url, :owner => owner) ensure File.delete srpm_file if defined?(srpm_file) end From 17e143e011d2ceb2f8de8f16cc0cb5cb47787fff Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Nov 2013 21:14:37 +0400 Subject: [PATCH 12/17] #321: use tmpfs folder --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 86c10b35a..a4a403c35 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -117,7 +117,7 @@ class Project < ActiveRecord::Base repository = Repository.find add_to_repository_id platform = repository.platform - dir = Dir.mktmpdir('mass-import-', '/tmp') + dir = Dir.mktmpdir('mass-import-', '/dev/shm') links.each do |link| begin package = link.attributes['href'].value From 77b23780bedb65775a7ae8f1604d5dceac26f737 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Nov 2013 23:02:19 +0400 Subject: [PATCH 13/17] #321: small fixes, added specs --- app/models/key_pair.rb | 2 +- app/models/project.rb | 9 +++++---- config/application.yml.sample | 3 +++ spec/models/project_spec.rb | 13 +++++++++++++ spec/spec_helper.rb | 5 +++-- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/models/key_pair.rb b/app/models/key_pair.rb index 17fb6c708..4c95c0d14 100644 --- a/app/models/key_pair.rb +++ b/app/models/key_pair.rb @@ -19,7 +19,7 @@ class KeyPair < ActiveRecord::Base protected def check_keys - dir = Dir.mktmpdir('keys-', '/tmp') + dir = Dir.mktmpdir 'keys-', APP_CONFIG['tmpfs_path'] begin %w(pubring secring).each do |kind| filename = "#{dir}/#{kind}" diff --git a/app/models/project.rb b/app/models/project.rb index a4a403c35..67821d166 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -117,13 +117,14 @@ class Project < ActiveRecord::Base repository = Repository.find add_to_repository_id platform = repository.platform - dir = Dir.mktmpdir('mass-import-', '/dev/shm') + dir = Dir.mktmpdir 'mass-import-', APP_CONFIG['tmpfs_path'] links.each do |link| begin package = link.attributes['href'].value package.chomp!; package.strip! next if package.size == 0 || package !~ /^[\w\.\-]+$/ + next if filter.present? && !filter.include?(package) uri = URI "#{url}/#{package}" srpm_file = "#{dir}/#{package}" @@ -137,7 +138,7 @@ class Project < ActiveRecord::Base end end if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? - next if owner.projects.exists?(:name => name) || (filter.present? && !filter.include?(name)) + next if owner.projects.exists?(:name => name) description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`) project = owner.projects.build( :name => name, @@ -156,11 +157,11 @@ class Project < ActiveRecord::Base f.close if defined?(f) Airbrake.notify_or_ignore(e, :link => link.to_s, :url => url, :owner => owner) ensure - File.delete srpm_file if defined?(srpm_file) + File.delete srpm_file if srpm_file end end ensure - FileUtils.remove_entry_secure dir if defined?(dir) + FileUtils.remove_entry_secure dir if dir end end diff --git a/config/application.yml.sample b/config/application.yml.sample index d20d851d3..f2824c609 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -57,6 +57,7 @@ development: <<: *common root_path: /var/rosa git_path: /var/rosa + tmpfs_path: /dev/shm do-not-reply-email: do-not-reply@localhost github_services: ip: 127.0.0.1 @@ -66,6 +67,7 @@ production: <<: *common root_path: /share git_path: /mnt/gitstore + tmpfs_path: /dev/shm do-not-reply-email: do-not-reply@abf.rosalinux.ru mailer_https_url: false github_services: @@ -74,6 +76,7 @@ production: test: <<: *common + tmpfs_path: "use Rails.root/tmp/test_root in spec" root_path: "use Rails.root/tmp/test_root in spec" git_path: "use Rails.root/tmp/test_root in spec" do-not-reply-email: do-not-reply@localhost diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 25d0c2e0e..64e0e3e73 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -169,4 +169,17 @@ describe Project do end end + it '#run_mass_import' do + owner = FactoryGirl.create(:user) + repository = FactoryGirl.create(:repository) + url = 'http://abf-downloads.rosalinux.ru/abf_personal/repository/test-mass-import' + visibility = 'open' + + Project.run_mass_import(url, "abf-worker-service-1-3.src.rpm\nredir-2.2.1-7.res6.src.rpm\n", visibility, owner, repository.id) + + Project.count.should == 2 + repository.projects.should have(2).items + owner.projects.should have(2).items + end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ea7b659ae..8d78688e2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -50,8 +50,9 @@ def stub_symlink_methods end Resque.inline = true -APP_CONFIG['root_path'] = "#{Rails.root}/tmp/test_root" -APP_CONFIG['git_path'] = "#{Rails.root}/tmp/test_root" +APP_CONFIG['root_path'] = "#{Rails.root}/tmp/test_root" +APP_CONFIG['git_path'] = "#{Rails.root}/tmp/test_root" +APP_CONFIG['tmpfs_path'] = "#{Rails.root}/tmp/test_root" def init_test_root clear_test_root From 1c961deceda532c8edcb7581d3163fce371f4248 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Nov 2013 23:36:37 +0400 Subject: [PATCH 14/17] #321: added specs --- app/models/ability.rb | 2 +- spec/models/cancan_spec.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 01baddc0c..30cde50a3 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -60,7 +60,7 @@ class Ability can :remove_user, Group can :create, Project - can([:mass_import, :run_mass_import], Project) if user.platforms.select(&:main?).find{ |p| local_admin?(p) }.present? + can([:mass_import, :run_mass_import], Project) if user.platforms.main.find{ |p| local_admin?(p) }.present? can :read, Project, :visibility => 'open' can [:read, :archive, :membered, :get_id], Project, :owner_type => 'User', :owner_id => user.id can [:read, :archive, :membered, :get_id], Project, :owner_type => 'Group', :owner_id => user.group_ids diff --git a/spec/models/cancan_spec.rb b/spec/models/cancan_spec.rb index 3e6a8377a..ec1d16d33 100644 --- a/spec/models/cancan_spec.rb +++ b/spec/models/cancan_spec.rb @@ -65,6 +65,12 @@ describe CanCan do end end + [:mass_import, :run_mass_import].each do |action| + it "should not be able to #{ action } project" do + @ability.should_not be_able_to(action, Project) + end + end + it 'should not be able to update register request' do @ability.should_not be_able_to(:update, register_request) end @@ -93,6 +99,12 @@ describe CanCan do end end + [:mass_import, :run_mass_import].each do |action| + it "should not be able to #{ action } project" do + @ability.should_not be_able_to(action, Project) + end + end + it "shoud be able to show user profile" do @ability.should be_able_to(:show, User) end @@ -260,6 +272,13 @@ describe CanCan do before(:each) do @platform.owner = @user @platform.save + @ability = Ability.new(@user) + end + + [:mass_import, :run_mass_import].each do |action| + it "should be able to #{ action } project" do + @ability.should be_able_to(action, Project) + end end [:read, :update, :destroy, :change_visibility].each do |action| @@ -272,6 +291,13 @@ describe CanCan do context 'with read rights' do before(:each) do @platform.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'reader') + @ability = Ability.new(@user) + end + + [:mass_import, :run_mass_import].each do |action| + it "should not be able to #{ action } project" do + @ability.should_not be_able_to(action, Project) + end end it "should be able to read platform" do From 22b397b6706f2b6683556d9c76005a0c3156034e Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 18 Nov 2013 15:27:59 +0400 Subject: [PATCH 15/17] #321: move #run_mass_import into module --- app/models/project.rb | 61 -------------------------------------- lib/modules/models/git.rb | 62 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 61 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 67821d166..a4fef26e8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,12 +1,7 @@ # -*- encoding : utf-8 -*- -require 'nokogiri' -require 'open-uri' -require 'iconv' - class Project < ActiveRecord::Base VISIBILITIES = ['open', 'hidden'] MAX_OWN_PROJECTS = 32000 - MAX_SRC_SIZE = 1024*1024*256 NAME_REGEXP = /[\w\-\+\.]+/ belongs_to :owner, :polymorphic => true, :counter_cache => :own_projects_count @@ -108,62 +103,6 @@ class Project < ActiveRecord::Base def find_by_owner_and_name!(owner_name, project_name) find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound end - - def run_mass_import(url, srpms_list, visibility, owner, add_to_repository_id) - doc = Nokogiri::HTML(open(url)) - links = doc.css("a[href$='.src.rpm']") - return if links.count == 0 - filter = srpms_list.lines.map(&:chomp).map(&:strip).select(&:present?) - - repository = Repository.find add_to_repository_id - platform = repository.platform - dir = Dir.mktmpdir 'mass-import-', APP_CONFIG['tmpfs_path'] - links.each do |link| - begin - package = link.attributes['href'].value - package.chomp!; package.strip! - - next if package.size == 0 || package !~ /^[\w\.\-]+$/ - next if filter.present? && !filter.include?(package) - - uri = URI "#{url}/#{package}" - srpm_file = "#{dir}/#{package}" - Net::HTTP.start(uri.host) do |http| - if http.request_head(uri.path)['content-length'].to_i < MAX_SRC_SIZE - f = open(srpm_file, 'wb') - http.request_get(uri.path) do |resp| - resp.read_body{ |segment| f.write(segment) } - end - f.close - end - end - if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? - next if owner.projects.exists?(:name => name) - description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`) - project = owner.projects.build( - :name => name, - :description => description, - :visibility => visibility, - :is_package => false # See: Hook for #attach_to_personal_repository - ) - project.owner = owner - if project.save - repository.projects << project rescue nil - project.update_attributes(:is_package => true) - project.import_srpm srpm_file, platform.name - end - end - rescue => e - f.close if defined?(f) - Airbrake.notify_or_ignore(e, :link => link.to_s, :url => url, :owner => owner) - ensure - File.delete srpm_file if srpm_file - end - end - ensure - FileUtils.remove_entry_secure dir if dir - end - end def init_mass_import diff --git a/lib/modules/models/git.rb b/lib/modules/models/git.rb index 246652074..169d36869 100644 --- a/lib/modules/models/git.rb +++ b/lib/modules/models/git.rb @@ -1,4 +1,8 @@ # -*- encoding : utf-8 -*- +require 'nokogiri' +require 'open-uri' +require 'iconv' + module Modules module Models module Git @@ -173,10 +177,68 @@ module Modules end module ClassMethods + MAX_SRC_SIZE = 1024*1024*256 + def process_hook(owner_uname, repo, newrev, oldrev, ref, newrev_type, user = nil, message = nil) rec = GitHook.new(owner_uname, repo, newrev, oldrev, ref, newrev_type, user, message) Modules::Observers::ActivityFeed::Git.create_notifications rec end + + def run_mass_import(url, srpms_list, visibility, owner, add_to_repository_id) + doc = Nokogiri::HTML(open(url)) + links = doc.css("a[href$='.src.rpm']") + return if links.count == 0 + filter = srpms_list.lines.map(&:chomp).map(&:strip).select(&:present?) + + repository = Repository.find add_to_repository_id + platform = repository.platform + dir = Dir.mktmpdir 'mass-import-', APP_CONFIG['tmpfs_path'] + links.each do |link| + begin + package = link.attributes['href'].value + package.chomp!; package.strip! + + next if package.size == 0 || package !~ /^[\w\.\-]+$/ + next if filter.present? && !filter.include?(package) + + uri = URI "#{url}/#{package}" + srpm_file = "#{dir}/#{package}" + Net::HTTP.start(uri.host) do |http| + if http.request_head(uri.path)['content-length'].to_i < MAX_SRC_SIZE + f = open(srpm_file, 'wb') + http.request_get(uri.path) do |resp| + resp.read_body{ |segment| f.write(segment) } + end + f.close + end + end + if name = `rpm -q --qf '[%{Name}]' -p #{srpm_file}` and $?.success? and name.present? + next if owner.projects.exists?(:name => name) + description = ::Iconv.conv('UTF-8//IGNORE', 'UTF-8', `rpm -q --qf '[%{Description}]' -p #{srpm_file}`) + project = owner.projects.build( + :name => name, + :description => description, + :visibility => visibility, + :is_package => false # See: Hook for #attach_to_personal_repository + ) + project.owner = owner + if project.save + repository.projects << project rescue nil + project.update_attributes(:is_package => true) + project.import_srpm srpm_file, platform.name + end + end + rescue => e + f.close if defined?(f) + Airbrake.notify_or_ignore(e, :link => link.to_s, :url => url, :owner => owner) + ensure + File.delete srpm_file if srpm_file + end + end + ensure + FileUtils.remove_entry_secure dir if dir + end + end end end From 7a872078edc0a7e858aa654c3a58861945ce2341 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 18 Nov 2013 16:31:48 +0400 Subject: [PATCH 16/17] #321: added rescue block into #run_mass_import --- lib/modules/models/git.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/modules/models/git.rb b/lib/modules/models/git.rb index 169d36869..c60ca5869 100644 --- a/lib/modules/models/git.rb +++ b/lib/modules/models/git.rb @@ -235,6 +235,8 @@ module Modules File.delete srpm_file if srpm_file end end + rescue => e + Airbrake.notify_or_ignore(e, :url => url, :owner => owner) ensure FileUtils.remove_entry_secure dir if dir end From e30920d1854dc37472cb6c7097e7b49fa644589f Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 18 Nov 2013 18:59:12 +0400 Subject: [PATCH 17/17] Cleanup old packages from testing sub repository --- app/models/build_list.rb | 4 ++-- lib/abf_worker/build_lists_publish_task_manager.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index f4a3260a4..5bf4216c4 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -427,12 +427,12 @@ class BuildList < ActiveRecord::Base new_core? ? abf_worker_log : I18n.t('layout.build_lists.log.not_available') end - def last_published + def last_published(testing = false) BuildList.where(:project_id => self.project_id, :save_to_repository_id => self.save_to_repository_id) .for_platform(self.build_for_platform_id) .scoped_to_arch(self.arch_id) - .for_status(BUILD_PUBLISHED) + .for_status(testing ? BUILD_PUBLISHED_INTO_TESTING : BUILD_PUBLISHED) .recent end diff --git a/lib/abf_worker/build_lists_publish_task_manager.rb b/lib/abf_worker/build_lists_publish_task_manager.rb index c98d6fcc5..2e4996695 100644 --- a/lib/abf_worker/build_lists_publish_task_manager.rb +++ b/lib/abf_worker/build_lists_publish_task_manager.rb @@ -132,7 +132,7 @@ module AbfWorker old_packages = packages_structure build_lists_for_cleanup.each do |bl| - bl.last_published.includes(:packages).limit(2).each{ |old_bl| + bl.last_published(testing).includes(:packages).limit(2).each{ |old_bl| fill_packages(old_bl, old_packages, :fullname) } end @@ -309,7 +309,7 @@ module AbfWorker # remove duplicates of sources for different arches bl.packages.by_package_type('source').each{ |s| new_sources["#{s.fullname}"] = s.sha1 } self.class.fill_packages(bl, packages) - bl.last_published.includes(:packages).limit(2).each{ |old_bl| + bl.last_published(testing).includes(:packages).limit(2).each{ |old_bl| self.class.fill_packages(old_bl, old_packages, :fullname) } build_list_ids << bl.id