2011-10-13 16:55:03 +01:00
|
|
|
class ProjectToRepository < ActiveRecord::Base
|
|
|
|
belongs_to :project
|
|
|
|
belongs_to :repository
|
2011-10-28 12:16:32 +01:00
|
|
|
|
|
|
|
delegate :path, :to => :project
|
2011-10-19 14:14:53 +01:00
|
|
|
|
2011-10-28 12:16:32 +01:00
|
|
|
#before_save :create_link
|
2011-10-28 13:40:38 +01:00
|
|
|
#before_save :add_compability_link
|
2011-10-28 12:16:32 +01:00
|
|
|
#after_destroy :remove_link
|
2011-10-28 13:40:38 +01:00
|
|
|
#after_destroy :remove_compability_link
|
2011-10-28 00:37:19 +01:00
|
|
|
|
|
|
|
after_create lambda {
|
2011-10-28 14:53:46 +01:00
|
|
|
project.xml_rpc_create(repository)
|
2011-10-28 14:32:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
after_destroy lambda {
|
2011-10-28 14:53:46 +01:00
|
|
|
project.xml_rpc_destroy(repository)
|
2011-10-28 00:37:19 +01:00
|
|
|
}
|
2011-10-19 14:14:53 +01:00
|
|
|
|
2011-10-28 12:16:32 +01:00
|
|
|
#def path
|
|
|
|
# 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"
|
2011-10-19 14:14:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2011-10-28 12:16:32 +01:00
|
|
|
#def build_path(dir)
|
|
|
|
# File.join(repository.path, dir)
|
|
|
|
#end
|
2011-10-19 14:14:53 +01:00
|
|
|
|
2011-10-28 12:16:32 +01:00
|
|
|
#def create_link
|
|
|
|
# exists = File.exists?(path) && File.directory?(path)
|
|
|
|
# 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
|
2011-10-19 14:14:53 +01:00
|
|
|
if new_record?
|
2011-10-28 12:45:00 +01:00
|
|
|
#FileUtils.ln_s(path, sym_path)
|
|
|
|
system("sudo ln -s #{ path } #{ sym_path }")
|
2011-10-19 14:14:53 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-28 12:16:32 +01:00
|
|
|
def remove_compability_link
|
|
|
|
exists = File.exists?(sym_path) && File.directory?(sym_path)
|
|
|
|
return false unless exists
|
2011-10-28 12:45:00 +01:00
|
|
|
#FileUtils.rm_rf(sym_path)
|
|
|
|
system("sudo rm -rf #{ sym_path }")
|
2011-10-19 14:14:53 +01:00
|
|
|
end
|
2011-10-13 16:55:03 +01:00
|
|
|
end
|