Fix repository and project_to_repository paths and symbolinks

This commit is contained in:
konstantin.grabar 2011-10-28 15:16:32 +04:00
parent 6238012fa9
commit 8f459f8abc
2 changed files with 61 additions and 39 deletions

View File

@ -2,35 +2,57 @@ class ProjectToRepository < ActiveRecord::Base
belongs_to :project belongs_to :project
belongs_to :repository belongs_to :repository
before_save :create_link delegate :path, :to => :project
after_destroy :remove_link
#before_save :create_link
before_save :add_compability_link
#after_destroy :remove_link
after_destroy :remove_compability_link
after_create lambda { after_create lambda {
project.xml_rpc_create project.xml_rpc_create
} }
def path #def path
build_path(project.unixname) # build_path(project.unixname)
#end
# This is symbolink to /git_projects/<owner.uname>/<unixname>.git
def sym_path
"#{ repository.platform.path }/projects/#{ project.unixname }.git"
end end
protected protected
def build_path(dir) #def build_path(dir)
File.join(repository.path, dir) # File.join(repository.path, dir)
end #end
def create_link #def create_link
exists = File.exists?(path) && File.directory?(path) # exists = File.exists?(path) && File.directory?(path)
raise "Symlink #{path} already exists" if exists # raise "Symlink #{path} already exists" if exists
# if new_record?
# FileUtils.ln_s(project.path, path)
# end
#end
#
#def remove_link
# exists = File.exists?(path) && File.directory?(path)
# raise "Directory #{path} didn't exists" unless exists
# FileUtils.rm_rf(path)
#end
def add_compability_link
exists = File.exists?(sym_path) && File.directory?(sym_path)
return false if exists
if new_record? if new_record?
FileUtils.ln_s(project.path, path) FileUtils.ln_s(path, sym_path)
end end
end end
def remove_link def remove_compability_link
exists = File.exists?(path) && File.directory?(path) exists = File.exists?(sym_path) && File.directory?(sym_path)
raise "Directory #{path} didn't exists" unless exists return false unless exists
FileUtils.rm_rf(path) FileUtils.rm_rf(sym_path)
end end
end end

View File

@ -29,9 +29,9 @@ class Repository < ActiveRecord::Base
attr_accessible :visibility, :name, :unixname, :platform_id attr_accessible :visibility, :name, :unixname, :platform_id
def path # def path
build_path(unixname) # build_path(unixname)
end # end
def clone def clone
r = Repository.new r = Repository.new
@ -50,26 +50,26 @@ class Repository < ActiveRecord::Base
end end
end end
def build_path(dir) # def build_path(dir)
File.join(platform.path, dir) # File.join(platform.path, dir)
end # end
#
def create_directory # def create_directory
exists = File.exists?(path) && File.directory?(path) # exists = File.exists?(path) && File.directory?(path)
raise "Directory #{path} already exists" if exists # raise "Directory #{path} already exists" if exists
if new_record? # if new_record?
FileUtils.mkdir_p(path) # FileUtils.mkdir_p(path)
%w(release updates).each { |subrep| FileUtils.mkdir_p(path + subrep) } # %w(release updates).each { |subrep| FileUtils.mkdir_p(path + subrep) }
elsif unixname_changed? # elsif unixname_changed?
FileUtils.mv(build_path(unixname_was), buildpath(unixname)) # FileUtils.mv(build_path(unixname_was), buildpath(unixname))
end # end
end # end
#
def remove_directory # def remove_directory
exists = File.exists?(path) && File.directory?(path) # exists = File.exists?(path) && File.directory?(path)
raise "Directory #{path} didn't exists" unless exists # raise "Directory #{path} didn't exists" unless exists
FileUtils.rm_rf(path) # FileUtils.rm_rf(path)
end # end
def xml_rpc_create def xml_rpc_create
result = BuildServer.create_repo unixname, platform.unixname result = BuildServer.create_repo unixname, platform.unixname