Commit eb626edd3fe2602321080e231cf748afc86d4700
1 parent
4d0af232
Exists in
master
and in
4 other branches
Replace all stat command line calls with ruby equivalents
Showing
2 changed files
with
17 additions
and
9 deletions
Show diff stats
lib/tasks/gitlab/check.rake
| ... | ... | @@ -502,7 +502,7 @@ namespace :gitlab do |
| 502 | 502 | return |
| 503 | 503 | end |
| 504 | 504 | |
| 505 | - if `stat --printf %a #{gitolite_config_path}` == "750" | |
| 505 | + if File.stat(gitolite_config_path).mode.to_s(8).ends_with?("750") | |
| 506 | 506 | puts "yes".green |
| 507 | 507 | else |
| 508 | 508 | puts "no".red |
| ... | ... | @@ -526,12 +526,11 @@ namespace :gitlab do |
| 526 | 526 | return |
| 527 | 527 | end |
| 528 | 528 | |
| 529 | - if `stat --printf %U #{gitolite_config_path}` == gitolite_ssh_user && # user | |
| 530 | - `stat --printf %G #{gitolite_config_path}` == gitolite_ssh_user #group | |
| 529 | + if File.stat(gitolite_config_path).uid == uid_for(gitolite_ssh_user) && | |
| 530 | + File.stat(gitolite_config_path).gid == gid_for(gitolite_ssh_user) | |
| 531 | 531 | puts "yes".green |
| 532 | 532 | else |
| 533 | 533 | puts "no".red |
| 534 | - puts "#{gitolite_config_path} is not owned by #{gitolite_ssh_user}".red | |
| 535 | 534 | try_fixing_it( |
| 536 | 535 | "sudo chown -R #{gitolite_ssh_user}:#{gitolite_ssh_user} #{gitolite_config_path}" |
| 537 | 536 | ) |
| ... | ... | @@ -722,7 +721,7 @@ namespace :gitlab do |
| 722 | 721 | return |
| 723 | 722 | end |
| 724 | 723 | |
| 725 | - if `stat --printf %a #{repo_base_path}` == "6770" | |
| 724 | + if File.stat(repo_base_path).mode.to_s(8).ends_with?("6770") | |
| 726 | 725 | puts "yes".green |
| 727 | 726 | else |
| 728 | 727 | puts "no".red |
| ... | ... | @@ -746,12 +745,11 @@ namespace :gitlab do |
| 746 | 745 | return |
| 747 | 746 | end |
| 748 | 747 | |
| 749 | - if `stat --printf %U #{repo_base_path}` == gitolite_ssh_user && # user | |
| 750 | - `stat --printf %G #{repo_base_path}` == gitolite_ssh_user #group | |
| 748 | + if File.stat(repo_base_path).uid == uid_for(gitolite_ssh_user) && | |
| 749 | + File.stat(repo_base_path).gid == gid_for(gitolite_ssh_user) | |
| 751 | 750 | puts "yes".green |
| 752 | 751 | else |
| 753 | 752 | puts "no".red |
| 754 | - puts "#{repo_base_path} is not owned by #{gitolite_ssh_user}".red | |
| 755 | 753 | try_fixing_it( |
| 756 | 754 | "sudo chown -R #{gitolite_ssh_user}:#{gitolite_ssh_user} #{repo_base_path}" |
| 757 | 755 | ) |
| ... | ... | @@ -832,7 +830,8 @@ namespace :gitlab do |
| 832 | 830 | next |
| 833 | 831 | end |
| 834 | 832 | |
| 835 | - if run_and_match("stat --format %N #{project_hook_file}", /#{hook_file}.+->.+#{gitolite_hook_file}/) | |
| 833 | + if File.lstat(project_hook_file).symlink? && | |
| 834 | + File.realpath(project_hook_file) == File.realpath(gitolite_hook_file) | |
| 836 | 835 | puts "ok".green |
| 837 | 836 | else |
| 838 | 837 | puts "not a link to Gitolite's hook".red | ... | ... |
lib/tasks/gitlab/task_helpers.rake
| ... | ... | @@ -45,6 +45,15 @@ namespace :gitlab do |
| 45 | 45 | end |
| 46 | 46 | end |
| 47 | 47 | |
| 48 | + def uid_for(user_name) | |
| 49 | + run("id -u #{user_name}").chomp.to_i | |
| 50 | + end | |
| 51 | + | |
| 52 | + def gid_for(group_name) | |
| 53 | + group_line = File.read("/etc/group").lines.select{|l| l.start_with?("#{group_name}:")}.first | |
| 54 | + group_line.split(":")[2].to_i | |
| 55 | + end | |
| 56 | + | |
| 48 | 57 | def warn_user_is_not_gitlab |
| 49 | 58 | unless @warned_user_not_gitlab |
| 50 | 59 | current_user = run("whoami").chomp | ... | ... |