From 8f459f8abcbd10dd2cbc162a68f3a6c28a9e52eb Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 28 Oct 2011 15:16:32 +0400 Subject: [PATCH] Fix repository and project_to_repository paths and symbolinks --- app/models/project_to_repository.rb | 54 ++++++++++++++++++++--------- app/models/repository.rb | 46 ++++++++++++------------ 2 files changed, 61 insertions(+), 39 deletions(-) diff --git a/app/models/project_to_repository.rb b/app/models/project_to_repository.rb index b920c09bf..91a468c78 100644 --- a/app/models/project_to_repository.rb +++ b/app/models/project_to_repository.rb @@ -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//.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 diff --git a/app/models/repository.rb b/app/models/repository.rb index 66c6f48b4..af77a1d88 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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