Commit 2b816075dc71dfe8f6f9e5349fdff7f03ad9dad0
1 parent
a9dcfd85
Exists in
spb-stable
and in
3 other branches
Replace backticks with Gitlab::Popen
Showing
8 changed files
with
33 additions
and
24 deletions
Show diff stats
app/controllers/admin/background_jobs_controller.rb
| 1 | 1 | class Admin::BackgroundJobsController < Admin::ApplicationController |
| 2 | 2 | def show |
| 3 | - @sidekiq_processes = `ps -U #{Settings.gitlab.user} -o euser,pid,pcpu,pmem,stat,start,command | grep sidekiq | grep -v grep` | |
| 3 | + ps_output, _ = Gitlab::Popen.popen(%W(ps -U #{Settings.gitlab.user} -o euser,pid,pcpu,pmem,stat,start,command)) | |
| 4 | + @sidekiq_processes = ps_output.split("\n").grep(/sidekiq/) | |
| 4 | 5 | end |
| 5 | 6 | end | ... | ... |
config/initializers/2_app.rb
lib/backup/manager.rb
| ... | ... | @@ -8,7 +8,7 @@ module Backup |
| 8 | 8 | s[:db_version] = "#{ActiveRecord::Migrator.current_version}" |
| 9 | 9 | s[:backup_created_at] = Time.now |
| 10 | 10 | s[:gitlab_version] = Gitlab::VERSION |
| 11 | - s[:tar_version] = %x{tar --version | head -1}.gsub(/\n/,"") | |
| 11 | + s[:tar_version] = tar_version | |
| 12 | 12 | |
| 13 | 13 | Dir.chdir(Gitlab.config.backup.path) |
| 14 | 14 | |
| ... | ... | @@ -98,5 +98,10 @@ module Backup |
| 98 | 98 | exit 1 |
| 99 | 99 | end |
| 100 | 100 | end |
| 101 | + | |
| 102 | + def tar_version | |
| 103 | + tar_version, _ = Gitlab::Popen.popen(%W(tar --version)) | |
| 104 | + tar_version.split("\n").first | |
| 105 | + end | |
| 101 | 106 | end |
| 102 | 107 | end | ... | ... |
lib/gitlab/logger.rb
| ... | ... | @@ -11,12 +11,14 @@ module Gitlab |
| 11 | 11 | def self.read_latest |
| 12 | 12 | path = Rails.root.join("log", file_name) |
| 13 | 13 | self.build unless File.exist?(path) |
| 14 | - logs = `tail -n 2000 #{path}`.split("\n") | |
| 14 | + tail_output, _ = Gitlab::Popen.popen(%W(tail -n 2000 #{path})) | |
| 15 | + tail_output.split("\n") | |
| 15 | 16 | end |
| 16 | 17 | |
| 17 | 18 | def self.read_latest_for filename |
| 18 | 19 | path = Rails.root.join("log", filename) |
| 19 | - logs = `tail -n 2000 #{path}`.split("\n") | |
| 20 | + tail_output, _ = Gitlab::Popen.popen(%W(tail -n 2000 #{path})) | |
| 21 | + tail_output.split("\n") | |
| 20 | 22 | end |
| 21 | 23 | |
| 22 | 24 | def self.build | ... | ... |
lib/gitlab/upgrader.rb
| ... | ... | @@ -42,8 +42,9 @@ module Gitlab |
| 42 | 42 | end |
| 43 | 43 | |
| 44 | 44 | def latest_version_raw |
| 45 | - git_tags = `git ls-remote --tags origin | grep tags\/v#{current_version.major}` | |
| 46 | - git_tags = git_tags.lines.to_a.select { |version| version =~ /v\d\.\d\.\d\Z/ } | |
| 45 | + remote_tags, _ = Gitlab::Popen.popen(%W(git ls-remote --tags origin)) | |
| 46 | + git_tags = remote_tags.split("\n").grep(/tags\/v#{current_version.major}/) | |
| 47 | + git_tags = git_tags.select { |version| version =~ /v\d\.\d\.\d\Z/ } | |
| 47 | 48 | last_tag = git_tags.last.match(/v\d\.\d\.\d/).to_s |
| 48 | 49 | end |
| 49 | 50 | ... | ... |
lib/tasks/gitlab/check.rake
| ... | ... | @@ -168,7 +168,7 @@ namespace :gitlab do |
| 168 | 168 | def check_migrations_are_up |
| 169 | 169 | print "All migrations up? ... " |
| 170 | 170 | |
| 171 | - migration_status = `bundle exec rake db:migrate:status` | |
| 171 | + migration_status, _ = Gitlab::Popen.popen(%W(bundle exec rake db:migrate:status)) | |
| 172 | 172 | |
| 173 | 173 | unless migration_status =~ /down\s+\d{14}/ |
| 174 | 174 | puts "yes".green |
| ... | ... | @@ -295,7 +295,7 @@ namespace :gitlab do |
| 295 | 295 | "user.email" => Gitlab.config.gitlab.email_from |
| 296 | 296 | } |
| 297 | 297 | correct_options = options.map do |name, value| |
| 298 | - run("git config --global --get #{name}").try(:squish) == value | |
| 298 | + run(%W(git config --global --get #{name})).try(:squish) == value | |
| 299 | 299 | end |
| 300 | 300 | |
| 301 | 301 | if correct_options.all? |
| ... | ... | @@ -628,7 +628,8 @@ namespace :gitlab do |
| 628 | 628 | end |
| 629 | 629 | |
| 630 | 630 | def sidekiq_process_count |
| 631 | - `ps ux`.scan(/sidekiq \d+\.\d+\.\d+/).count | |
| 631 | + ps_ux, _ = Gitlab::Popen.popen(%W(ps ux)) | |
| 632 | + ps_ux.scan(/sidekiq \d+\.\d+\.\d+/).count | |
| 632 | 633 | end |
| 633 | 634 | end |
| 634 | 635 | |
| ... | ... | @@ -739,7 +740,7 @@ namespace :gitlab do |
| 739 | 740 | |
| 740 | 741 | def check_git_version |
| 741 | 742 | required_version = Gitlab::VersionInfo.new(1, 7, 10) |
| 742 | - current_version = Gitlab::VersionInfo.parse(run("#{Gitlab.config.git.bin_path} --version")) | |
| 743 | + current_version = Gitlab::VersionInfo.parse(run(%W(#{Gitlab.config.git.bin_path} --version))) | |
| 743 | 744 | |
| 744 | 745 | puts "Your git bin path is \"#{Gitlab.config.git.bin_path}\"" |
| 745 | 746 | print "Git version >= #{required_version} ? ... " | ... | ... |
lib/tasks/gitlab/info.rake
| ... | ... | @@ -4,20 +4,20 @@ namespace :gitlab do |
| 4 | 4 | task info: :environment do |
| 5 | 5 | |
| 6 | 6 | # check if there is an RVM environment |
| 7 | - rvm_version = run_and_match("rvm --version", /[\d\.]+/).try(:to_s) | |
| 7 | + rvm_version = run_and_match(%W(rvm --version), /[\d\.]+/).try(:to_s) | |
| 8 | 8 | # check Ruby version |
| 9 | - ruby_version = run_and_match("ruby --version", /[\d\.p]+/).try(:to_s) | |
| 9 | + ruby_version = run_and_match(%W(ruby --version), /[\d\.p]+/).try(:to_s) | |
| 10 | 10 | # check Gem version |
| 11 | - gem_version = run("gem --version") | |
| 11 | + gem_version = run(%W(gem --version)) | |
| 12 | 12 | # check Bundler version |
| 13 | - bunder_version = run_and_match("bundle --version", /[\d\.]+/).try(:to_s) | |
| 13 | + bunder_version = run_and_match(%W(bundle --version), /[\d\.]+/).try(:to_s) | |
| 14 | 14 | # check Bundler version |
| 15 | - rake_version = run_and_match("rake --version", /[\d\.]+/).try(:to_s) | |
| 15 | + rake_version = run_and_match(%W(rake --version), /[\d\.]+/).try(:to_s) | |
| 16 | 16 | |
| 17 | 17 | puts "" |
| 18 | 18 | puts "System information".yellow |
| 19 | 19 | puts "System:\t\t#{os_name || "unknown".red}" |
| 20 | - puts "Current User:\t#{`whoami`}" | |
| 20 | + puts "Current User:\t#{run(%W(whoami))}" | |
| 21 | 21 | puts "Using RVM:\t#{rvm_version.present? ? "yes".green : "no"}" |
| 22 | 22 | puts "RVM Version:\t#{rvm_version}" if rvm_version.present? |
| 23 | 23 | puts "Ruby Version:\t#{ruby_version || "unknown".red}" | ... | ... |
lib/tasks/gitlab/task_helpers.rake
| ... | ... | @@ -28,7 +28,7 @@ namespace :gitlab do |
| 28 | 28 | # It will primarily use lsb_relase to determine the OS. |
| 29 | 29 | # It has fallbacks to Debian, SuSE, OS X and systems running systemd. |
| 30 | 30 | def os_name |
| 31 | - os_name = run("lsb_release -irs") | |
| 31 | + os_name = run(%W(lsb_release -irs)) | |
| 32 | 32 | os_name ||= if File.readable?('/etc/system-release') |
| 33 | 33 | File.read('/etc/system-release') |
| 34 | 34 | end |
| ... | ... | @@ -39,7 +39,7 @@ namespace :gitlab do |
| 39 | 39 | os_name ||= if File.readable?('/etc/SuSE-release') |
| 40 | 40 | File.read('/etc/SuSE-release') |
| 41 | 41 | end |
| 42 | - os_name ||= if os_x_version = run("sw_vers -productVersion") | |
| 42 | + os_name ||= if os_x_version = run(%W(sw_vers -productVersion)) | |
| 43 | 43 | "Mac OS X #{os_x_version}" |
| 44 | 44 | end |
| 45 | 45 | os_name ||= if File.readable?('/etc/os-release') |
| ... | ... | @@ -80,13 +80,12 @@ namespace :gitlab do |
| 80 | 80 | # |
| 81 | 81 | # see also #run_and_match |
| 82 | 82 | def run(command) |
| 83 | - unless `#{command} 2>/dev/null`.blank? | |
| 84 | - `#{command}` | |
| 85 | - end | |
| 83 | + output, _ = Gitlab::Popen.popen(command) | |
| 84 | + output | |
| 86 | 85 | end |
| 87 | 86 | |
| 88 | 87 | def uid_for(user_name) |
| 89 | - run("id -u #{user_name}").chomp.to_i | |
| 88 | + run(%W(id -u #{user_name})).chomp.to_i | |
| 90 | 89 | end |
| 91 | 90 | |
| 92 | 91 | def gid_for(group_name) |
| ... | ... | @@ -100,7 +99,7 @@ namespace :gitlab do |
| 100 | 99 | def warn_user_is_not_gitlab |
| 101 | 100 | unless @warned_user_not_gitlab |
| 102 | 101 | gitlab_user = Gitlab.config.gitlab.user |
| 103 | - current_user = run("whoami").chomp | |
| 102 | + current_user = run(%W(whoami)).chomp | |
| 104 | 103 | unless current_user == gitlab_user |
| 105 | 104 | puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}" |
| 106 | 105 | puts " You are running as user #{current_user.magenta}, we hope you know what you are doing." | ... | ... |