summaryrefslogtreecommitdiff
path: root/lib/tasks/gitlab
diff options
context:
space:
mode:
authorRiyad Preukschas <riyad@informatik.uni-bremen.de>2013-01-12 00:44:40 +0100
committerRiyad Preukschas <riyad@informatik.uni-bremen.de>2013-01-12 01:25:01 +0100
commiteb626edd3fe2602321080e231cf748afc86d4700 (patch)
tree4a12fa34cb4302289047c0dbfb79ea50d057ec7d /lib/tasks/gitlab
parent4d0af232da7df8c4a33b9f2e44933f1f3d2527bc (diff)
downloadgitlab-ce-eb626edd3fe2602321080e231cf748afc86d4700.tar.gz
Replace all stat command line calls with ruby equivalents
Diffstat (limited to 'lib/tasks/gitlab')
-rw-r--r--lib/tasks/gitlab/check.rake17
-rw-r--r--lib/tasks/gitlab/task_helpers.rake9
2 files changed, 17 insertions, 9 deletions
diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake
index 40a572c6a3c..623028b16d2 100644
--- a/lib/tasks/gitlab/check.rake
+++ b/lib/tasks/gitlab/check.rake
@@ -502,7 +502,7 @@ namespace :gitlab do
return
end
- if `stat --printf %a #{gitolite_config_path}` == "750"
+ if File.stat(gitolite_config_path).mode.to_s(8).ends_with?("750")
puts "yes".green
else
puts "no".red
@@ -526,12 +526,11 @@ namespace :gitlab do
return
end
- if `stat --printf %U #{gitolite_config_path}` == gitolite_ssh_user && # user
- `stat --printf %G #{gitolite_config_path}` == gitolite_ssh_user #group
+ if File.stat(gitolite_config_path).uid == uid_for(gitolite_ssh_user) &&
+ File.stat(gitolite_config_path).gid == gid_for(gitolite_ssh_user)
puts "yes".green
else
puts "no".red
- puts "#{gitolite_config_path} is not owned by #{gitolite_ssh_user}".red
try_fixing_it(
"sudo chown -R #{gitolite_ssh_user}:#{gitolite_ssh_user} #{gitolite_config_path}"
)
@@ -722,7 +721,7 @@ namespace :gitlab do
return
end
- if `stat --printf %a #{repo_base_path}` == "6770"
+ if File.stat(repo_base_path).mode.to_s(8).ends_with?("6770")
puts "yes".green
else
puts "no".red
@@ -746,12 +745,11 @@ namespace :gitlab do
return
end
- if `stat --printf %U #{repo_base_path}` == gitolite_ssh_user && # user
- `stat --printf %G #{repo_base_path}` == gitolite_ssh_user #group
+ if File.stat(repo_base_path).uid == uid_for(gitolite_ssh_user) &&
+ File.stat(repo_base_path).gid == gid_for(gitolite_ssh_user)
puts "yes".green
else
puts "no".red
- puts "#{repo_base_path} is not owned by #{gitolite_ssh_user}".red
try_fixing_it(
"sudo chown -R #{gitolite_ssh_user}:#{gitolite_ssh_user} #{repo_base_path}"
)
@@ -832,7 +830,8 @@ namespace :gitlab do
next
end
- if run_and_match("stat --format %N #{project_hook_file}", /#{hook_file}.+->.+#{gitolite_hook_file}/)
+ if File.lstat(project_hook_file).symlink? &&
+ File.realpath(project_hook_file) == File.realpath(gitolite_hook_file)
puts "ok".green
else
puts "not a link to Gitolite's hook".red
diff --git a/lib/tasks/gitlab/task_helpers.rake b/lib/tasks/gitlab/task_helpers.rake
index 5b5c3c30ba2..5dd97fa2f92 100644
--- a/lib/tasks/gitlab/task_helpers.rake
+++ b/lib/tasks/gitlab/task_helpers.rake
@@ -45,6 +45,15 @@ namespace :gitlab do
end
end
+ def uid_for(user_name)
+ run("id -u #{user_name}").chomp.to_i
+ end
+
+ def gid_for(group_name)
+ group_line = File.read("/etc/group").lines.select{|l| l.start_with?("#{group_name}:")}.first
+ group_line.split(":")[2].to_i
+ end
+
def warn_user_is_not_gitlab
unless @warned_user_not_gitlab
current_user = run("whoami").chomp