J
John Platte
I'm having a problem with File.expand_path(__FILE__) after a chdir.
Looks like a bug in Ruby to me. If someone can tell me what I'm doing
wrong, I'd be grateful.
Here's the reduction:
[ryan@kursk 15:26:38 ~]$ cat tmp/demo-problem.rb
puts "starting working directory: " + Dir.getwd
puts "expand_path: " + File.expand_path(__FILE__)
puts "about to change to dirname of __FILE__: " + __FILE__
Dir.chdir(File.dirname(__FILE__))
puts "new working directory: " + Dir.getwd
puts "expand_path: " + File.expand_path(__FILE__)
[ryan@kursk 15:26:40 ~]$ cd tmp
[ryan@kursk 15:26:44 ~/tmp]$ ruby demo-problem.rb
starting working directory: /Users/ryan/tmp
expand_path: /Users/ryan/tmp/demo-problem.rb
about to change to dirname of __FILE__: demo-problem.rb
new working directory: /Users/ryan/tmp
expand_path: /Users/ryan/tmp/demo-problem.rb
[ryan@kursk 15:26:45 ~/tmp]$ cd ..
[ryan@kursk 15:26:50 ~]$ ruby tmp/demo-problem.rb
starting working directory: /Users/ryan
expand_path: /Users/ryan/tmp/demo-problem.rb
about to change to dirname of __FILE__: tmp/demo-problem.rb
new working directory: /Users/ryan/tmp
expand_path: /Users/ryan/tmp/tmp/demo-problem.rb
[ryan@kursk 15:26:56 ~]$
Looks like a bug in Ruby to me. If someone can tell me what I'm doing
wrong, I'd be grateful.
Here's the reduction:
[ryan@kursk 15:26:38 ~]$ cat tmp/demo-problem.rb
puts "starting working directory: " + Dir.getwd
puts "expand_path: " + File.expand_path(__FILE__)
puts "about to change to dirname of __FILE__: " + __FILE__
Dir.chdir(File.dirname(__FILE__))
puts "new working directory: " + Dir.getwd
puts "expand_path: " + File.expand_path(__FILE__)
[ryan@kursk 15:26:40 ~]$ cd tmp
[ryan@kursk 15:26:44 ~/tmp]$ ruby demo-problem.rb
starting working directory: /Users/ryan/tmp
expand_path: /Users/ryan/tmp/demo-problem.rb
about to change to dirname of __FILE__: demo-problem.rb
new working directory: /Users/ryan/tmp
expand_path: /Users/ryan/tmp/demo-problem.rb
[ryan@kursk 15:26:45 ~/tmp]$ cd ..
[ryan@kursk 15:26:50 ~]$ ruby tmp/demo-problem.rb
starting working directory: /Users/ryan
expand_path: /Users/ryan/tmp/demo-problem.rb
about to change to dirname of __FILE__: tmp/demo-problem.rb
new working directory: /Users/ryan/tmp
expand_path: /Users/ryan/tmp/tmp/demo-problem.rb
[ryan@kursk 15:26:56 ~]$