Fix repository and project_to_repository paths and symbolinks
This commit is contained in:
parent
6238012fa9
commit
8f459f8abc
|
@ -1,36 +1,58 @@
|
|||
class ProjectToRepository < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
belongs_to :repository
|
||||
|
||||
delegate :path, :to => :project
|
||||
|
||||
before_save :create_link
|
||||
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 {
|
||||
project.xml_rpc_create
|
||||
}
|
||||
|
||||
def path
|
||||
build_path(project.unixname)
|
||||
#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"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def build_path(dir)
|
||||
File.join(repository.path, dir)
|
||||
end
|
||||
#def build_path(dir)
|
||||
# File.join(repository.path, dir)
|
||||
#end
|
||||
|
||||
def create_link
|
||||
exists = File.exists?(path) && File.directory?(path)
|
||||
raise "Symlink #{path} already exists" if exists
|
||||
#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
|
||||
if new_record?
|
||||
FileUtils.ln_s(project.path, path)
|
||||
FileUtils.ln_s(path, sym_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)
|
||||
def remove_compability_link
|
||||
exists = File.exists?(sym_path) && File.directory?(sym_path)
|
||||
return false unless exists
|
||||
FileUtils.rm_rf(sym_path)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -29,9 +29,9 @@ class Repository < ActiveRecord::Base
|
|||
|
||||
attr_accessible :visibility, :name, :unixname, :platform_id
|
||||
|
||||
def path
|
||||
build_path(unixname)
|
||||
end
|
||||
# def path
|
||||
# build_path(unixname)
|
||||
# end
|
||||
|
||||
def clone
|
||||
r = Repository.new
|
||||
|
@ -50,26 +50,26 @@ class Repository < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def build_path(dir)
|
||||
File.join(platform.path, dir)
|
||||
end
|
||||
|
||||
def create_directory
|
||||
exists = File.exists?(path) && File.directory?(path)
|
||||
raise "Directory #{path} already exists" if exists
|
||||
if new_record?
|
||||
FileUtils.mkdir_p(path)
|
||||
%w(release updates).each { |subrep| FileUtils.mkdir_p(path + subrep) }
|
||||
elsif unixname_changed?
|
||||
FileUtils.mv(build_path(unixname_was), buildpath(unixname))
|
||||
end
|
||||
end
|
||||
|
||||
def remove_directory
|
||||
exists = File.exists?(path) && File.directory?(path)
|
||||
raise "Directory #{path} didn't exists" unless exists
|
||||
FileUtils.rm_rf(path)
|
||||
end
|
||||
# def build_path(dir)
|
||||
# File.join(platform.path, dir)
|
||||
# end
|
||||
#
|
||||
# def create_directory
|
||||
# exists = File.exists?(path) && File.directory?(path)
|
||||
# raise "Directory #{path} already exists" if exists
|
||||
# if new_record?
|
||||
# FileUtils.mkdir_p(path)
|
||||
# %w(release updates).each { |subrep| FileUtils.mkdir_p(path + subrep) }
|
||||
# elsif unixname_changed?
|
||||
# FileUtils.mv(build_path(unixname_was), buildpath(unixname))
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def remove_directory
|
||||
# exists = File.exists?(path) && File.directory?(path)
|
||||
# raise "Directory #{path} didn't exists" unless exists
|
||||
# FileUtils.rm_rf(path)
|
||||
# end
|
||||
|
||||
def xml_rpc_create
|
||||
result = BuildServer.create_repo unixname, platform.unixname
|
||||
|
|
Loading…
Reference in New Issue