rosa-build/app/models/project_to_repository.rb

61 lines
1.7 KiB
Ruby
Raw Normal View History

class ProjectToRepository < ActiveRecord::Base
belongs_to :project
belongs_to :repository
delegate :path, :to => :project
2011-10-19 14:14:53 +01:00
#before_save :create_link
#before_save :add_compability_link
#after_destroy :remove_link
#after_destroy :remove_compability_link
after_create lambda { project.xml_rpc_create(repository) }, :unless => lambda {Thread.current[:skip]}
after_destroy lambda { project.xml_rpc_destroy(repository) }
after_rollback lambda { project.xml_rpc_destroy(repository) rescue true if new_record? }
2011-10-19 14:14:53 +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
#def build_path(dir)
# File.join(repository.path, dir)
#end
2011-10-19 14:14:53 +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
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
end