Gitlab::Gitolite final fixes. Seems like all functionality is working correctly now

This commit is contained in:
randx 2012-08-29 00:33:19 +03:00
parent e8e8ca940b
commit c48c0f95b2

View file

@ -10,14 +10,14 @@ module Gitlab
def set_key key_id, key_content, projects def set_key key_id, key_content, projects
configure do |c| configure do |c|
c.update_keys(key_id, key_content) c.update_keys(key_id, key_content)
c.update_project(project.path, projects) c.update_projects(projects)
end end
end end
def remove_key key_id, projects def remove_key key_id, projects
configure do |c| configure do |c|
c.delete_key(key_id) c.delete_key(key_id)
c.update_project(project.path, projects) c.update_projects(projects)
end end
end end
@ -50,43 +50,7 @@ module Gitlab
end end
end end
private protected
def pull
# create tmp dir
@local_dir = File.join(Rails.root, 'tmp',"gitlabhq-gitolite-#{Time.now.to_i}")
Dir.mkdir @local_dir
`git clone #{Gitlab.config.gitolite_admin_uri} #{@local_dir}/gitolite`
end
def push
Dir.chdir(File.join(@local_dir, "gitolite"))
`git add -A`
`git commit -am "Gitlab"`
`git push`
Dir.chdir(Rails.root)
FileUtils.rm_rf(@local_dir)
end
def configure
Timeout::timeout(30) do
File.open(File.join(Rails.root, 'tmp', "gitlabhq-gitolite.lock"), "w+") do |f|
begin
f.flock(File::LOCK_EX)
pull
yield(self)
push
ensure
f.flock(File::LOCK_UN)
end
end
end
rescue Exception => ex
Gitlab::Logger.error(ex.message)
raise Gitolite::AccessDenied.new("gitolite timeout")
end
def destroy_project(project) def destroy_project(project)
FileUtils.rm_rf(project.path_to_repo) FileUtils.rm_rf(project.path_to_repo)
@ -191,5 +155,43 @@ module Gitlab
conf.add_repo(repo, true) conf.add_repo(repo, true)
ga_repo.save ga_repo.save
end end
private
def pull
# create tmp dir
@local_dir = File.join(Rails.root, 'tmp',"gitlabhq-gitolite-#{Time.now.to_i}")
Dir.mkdir @local_dir
`git clone #{Gitlab.config.gitolite_admin_uri} #{@local_dir}/gitolite`
end
def push
Dir.chdir(File.join(@local_dir, "gitolite"))
`git add -A`
`git commit -am "Gitlab"`
`git push`
Dir.chdir(Rails.root)
FileUtils.rm_rf(@local_dir)
end
def configure
Timeout::timeout(30) do
File.open(File.join(Rails.root, 'tmp', "gitlabhq-gitolite.lock"), "w+") do |f|
begin
f.flock(File::LOCK_EX)
pull
yield(self)
push
ensure
f.flock(File::LOCK_UN)
end
end
end
rescue Exception => ex
Gitlab::Logger.error(ex.message)
raise Gitolite::AccessDenied.new("gitolite timeout")
end
end end
end end