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