From 22e5ab31b52a287705083ad6f3cad836ab96b619 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Wed, 10 Apr 2013 08:33:05 +0530 Subject: Searching for rails executable correctly * Current logic of finding Rails executable in parent directory is not returning full path of executable if it is found in one of the parent directories * To compensate for this, we have to call exec_app_rails recursively until the executable is found or we cant do 'chdir' anymore * This solution finds the correct executable path from parent directory(s) recursively --- railties/lib/rails/app_rails_loader.rb | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/app_rails_loader.rb b/railties/lib/rails/app_rails_loader.rb index 1c64f2dcc6..ef6fcd81b4 100644 --- a/railties/lib/rails/app_rails_loader.rb +++ b/railties/lib/rails/app_rails_loader.rb @@ -6,22 +6,22 @@ module Rails EXECUTABLES = ['bin/rails', 'script/rails'] def self.exec_app_rails - cwd = Dir.pwd - - exe = find_executable - exe ||= find_executable_in_parent_path - return unless exe + cwd = Dir.pwd + pathname = Pathname.new(Dir.pwd) + + until exe = find_executable + # Return to working directory if root is hit without finding executable + Dir.chdir(cwd) and return if pathname.root? + # Otherwise keep moving upwards in search of executable + Dir.chdir("..") + pathname = pathname.parent + end contents = File.read(exe) # This is the Rails executable, let's use it if contents =~ /(APP|ENGINE)_PATH/ - exec RUBY, exe, *ARGV if find_executable - Dir.chdir("..") do - # Recurse in a chdir block: if the search fails we want to be sure - # the application is generated in the original working directory. - exec_app_rails unless cwd == Dir.pwd - end + exec RUBY, exe, *ARGV # This is a Bundler binstub. Stop and explain how to upgrade. elsif exe =~ /bin\/rails$/ && contents =~ /This file was generated by Bundler/ @@ -59,10 +59,5 @@ generate it and add it to source control: EXECUTABLES.find { |exe| File.exists?(exe) } end - def self.find_executable_in_parent_path(path = Pathname.new(Dir.pwd).parent) - EXECUTABLES.find do |exe| - File.exists?(exe) || !path.root? && find_executable_in_parent_path(path.parent) - end - end end end -- cgit v1.2.3