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,7 +502,7 @@ namespace :gitlab do | ||
502 | return | 502 | return |
503 | end | 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 | puts "yes".green | 506 | puts "yes".green |
507 | else | 507 | else |
508 | puts "no".red | 508 | puts "no".red |
@@ -526,12 +526,11 @@ namespace :gitlab do | @@ -526,12 +526,11 @@ namespace :gitlab do | ||
526 | return | 526 | return |
527 | end | 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 | puts "yes".green | 531 | puts "yes".green |
532 | else | 532 | else |
533 | puts "no".red | 533 | puts "no".red |
534 | - puts "#{gitolite_config_path} is not owned by #{gitolite_ssh_user}".red | ||
535 | try_fixing_it( | 534 | try_fixing_it( |
536 | "sudo chown -R #{gitolite_ssh_user}:#{gitolite_ssh_user} #{gitolite_config_path}" | 535 | "sudo chown -R #{gitolite_ssh_user}:#{gitolite_ssh_user} #{gitolite_config_path}" |
537 | ) | 536 | ) |
@@ -722,7 +721,7 @@ namespace :gitlab do | @@ -722,7 +721,7 @@ namespace :gitlab do | ||
722 | return | 721 | return |
723 | end | 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 | puts "yes".green | 725 | puts "yes".green |
727 | else | 726 | else |
728 | puts "no".red | 727 | puts "no".red |
@@ -746,12 +745,11 @@ namespace :gitlab do | @@ -746,12 +745,11 @@ namespace :gitlab do | ||
746 | return | 745 | return |
747 | end | 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 | puts "yes".green | 750 | puts "yes".green |
752 | else | 751 | else |
753 | puts "no".red | 752 | puts "no".red |
754 | - puts "#{repo_base_path} is not owned by #{gitolite_ssh_user}".red | ||
755 | try_fixing_it( | 753 | try_fixing_it( |
756 | "sudo chown -R #{gitolite_ssh_user}:#{gitolite_ssh_user} #{repo_base_path}" | 754 | "sudo chown -R #{gitolite_ssh_user}:#{gitolite_ssh_user} #{repo_base_path}" |
757 | ) | 755 | ) |
@@ -832,7 +830,8 @@ namespace :gitlab do | @@ -832,7 +830,8 @@ namespace :gitlab do | ||
832 | next | 830 | next |
833 | end | 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 | puts "ok".green | 835 | puts "ok".green |
837 | else | 836 | else |
838 | puts "not a link to Gitolite's hook".red | 837 | puts "not a link to Gitolite's hook".red |
lib/tasks/gitlab/task_helpers.rake
@@ -45,6 +45,15 @@ namespace :gitlab do | @@ -45,6 +45,15 @@ namespace :gitlab do | ||
45 | end | 45 | end |
46 | end | 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 | def warn_user_is_not_gitlab | 57 | def warn_user_is_not_gitlab |
49 | unless @warned_user_not_gitlab | 58 | unless @warned_user_not_gitlab |
50 | current_user = run("whoami").chomp | 59 | current_user = run("whoami").chomp |