Skip to content
Browse files

go back to using tmpdir, instead of writing to rails root

  • Loading branch information...
1 parent 196ef2c commit 4187e52148e9d3d12133c0db281e6473c3caf5d5 @ericpaulbishop committed Apr 24, 2011
Showing with 27 additions and 8 deletions.
  1. +7 −0 Rakefile
  2. +20 −8 lib/git_hosting.rb
View
7 Rakefile
@@ -0,0 +1,7 @@
+begin
+ require 'tmpdir'
+ require 'lockfile'
+ require 'net/ssh'
+rescue
+ puts "need to install tmpdir lockfile and net/ssh gems"
+end
View
28 lib/git_hosting.rb
@@ -32,16 +32,22 @@ def self.add_route_for_project_with_map(p,m)
end
-
+ def self.get_tmp_dir
+ @@git_hosting_tmp_dir ||= File.join(Dir.tmpdir, "redmine_git_hosting_#{Time.now.to_i}")
+ if !File.directory?(@@git_hosting_tmp_dir)
+ %x[mkdir -p "#{@@git_hosting_tmp_dir}"]
+ end
+ return @@git_hosting_tmp_dir
+ end
def self.git_exec_path
- return File.join(RAILS_ROOT, "run_git_as_git_user")
+ return File.join(get_tmp_dir(), "run_git_as_git_user")
end
def self.gitolite_ssh_path
- return File.join(RAILS_ROOT, "gitolite_admin_ssh")
+ return File.join(get_tmp_dir(), "gitolite_admin_ssh")
end
def self.git_user_runner_path
- return File.join(RAILS_ROOT, "run_as_git_user")
+ return File.join(get_tmp_dir(), "run_as_git_user")
end
def self.git_exec
@@ -111,15 +117,21 @@ def self.update_repositories(projects)
# Don't bother doing anything if none of the projects we've been handed have a Git repository
unless projects.detect{|p| p.repository.is_a?(Repository::Git) }.nil?
+ #return cleanly if we don't have permissions to load identity file, which we need
+ if !File.owned?(Setting.plugin_redmine_git_hosting['gitUserIdentityFile'])
+ return
+ end
+
+
# create tmp dir, return cleanly if, for some reason, we don't have proper permissions
- local_dir = File.join(RAILS_ROOT, "tmp","redmine_gitolite_#{Time.now.to_i}")
- %x[mkdir "#{local_dir}"]
+ local_dir = File.join(get_tmp_dir(), "tmp_#{Time.now.to_i}")
+ %x[mkdir -p "#{local_dir}"]
if !File.exists? local_dir
return
end
#lock
- lockfile=File.new(File.join(RAILS_ROOT,"tmp",'redmine_gitolite_lock'),File::CREAT|File::RDONLY)
+ lockfile=File.new(File.join(get_tmp_dir(),'redmine_git_hosting_lock'),File::CREAT|File::RDONLY)
retries=5
loop do
break if lockfile.flock(File::LOCK_EX|File::LOCK_NB)
@@ -199,7 +211,7 @@ def self.update_repositories(projects)
end
if changed
- git_push_file = File.join(local_dir, 'git_push.bat')
+ git_push_file = File.join(local_dir, 'git_push.sh')
new_dir= File.join(local_dir,'gitolite')
File.open(git_push_file, "w") do |f|
f.puts "#!/bin/sh"

0 comments on commit 4187e52

Please sign in to comment.
Something went wrong with that request. Please try again.