Project

General

Profile

Actions

Feature #13300

closed

Strip chroot path from $LOADED_FEATURES when calling Dir.chroot

Added by jeremyevans0 (Jeremy Evans) over 5 years ago. Updated over 4 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:80004]

Description

Currently, Dir.chroot doesn't modify $LOADED_FEATURES, leading
to a situation where Kernel#require will attempt to load the same
file twice, or a different file not at all because it thinks it
is already loaded.

With this example code:

require 'fileutils'
File.write('baz.rb', 'A = 1')
require './baz'
pwd = Dir.pwd
Dir.chroot(pwd)
require './baz'
FileUtils.mkdir_p(pwd)
File.write(File.join(pwd, 'baz.rb'), '$a = 2')
require "#{pwd}/baz"
warn "$a => #{$a.inspect}" unless $a == 2

Previous output on stderr:

/baz.rb:1: warning: already initialized constant A
/home/billg/baz.rb:1: warning: previous definition of A was here
$a => nil

With this patch, no output on stderr.


Files

Actions

Also available in: Atom PDF