From: merch-redmine@... Date: 2017-03-11T03:29:04+00:00 Subject: [ruby-core:80008] [Ruby trunk Feature#13300] Strip chroot path from $LOADED_FEATURES when calling Dir.chroot Issue #13300 has been updated by Jeremy Evans. Thanks nobu, your patch is definitely better. I thought about stripping `$LOAD_PATH`, but I believe it would break backwards compatibility slightly, since `$LOAD_PATH` stores where to look for future loads/requires, and is not concerned about code previously required before `Dir.chroot`. For example, the behavior of the following code: ``` require 'fileutils' pwd = Dir.pwd $LOAD_PATH << File.join(pwd) Dir.chroot(pwd) File.write('foo.rb', '$a = 1') FileUtils.mkdir_p(pwd) File.write(File.join(pwd, 'foo.rb'), '$a = 2') require 'foo' p $a ``` would change from outputting `2` to outputting `1` if you started stripping `$LOAD_PATH`. That being said, I'm not opposed to stripping `$LOAD_PATH` as well as `$LOADED_FEATURES`, as I doubt there is significant amount of code that relies on the current behavior. ---------------------------------------- Feature #13300: Strip chroot path from $LOADED_FEATURES when calling Dir.chroot https://bugs.ruby-lang.org/issues/13300#change-63425 * Author: Jeremy Evans * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- 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: ~~~ ruby 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-------------------------------- 0001-Strip-chroot-path-from-LOADED_FEATURES-when-calling-.patch (2.6 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: