ActionsLike0
Bug #10222
closedrequire_relative and require should be compatible with each other when symlinks are used
Description
Not sure if this should be considered a bug or a feature request since I don't know whether the current behavior is intended or not.
Recently I got a report for my gem rails-web-console related to require_relative causing trouble with symlinked dirs:
https://github.com/rosenfeld/active_record_migrations/issues/6
Dmitry was able to replicate the issue using vanilla Ruby:
mkdir a
ln -s a b
echo "require_relative 'b'" > a/a.rb
echo "p 'b loaded'" > a/b.rb
echo "$: << File.expand_path('../b', __FILE__); require 'a'; require 'b'" > c.rb
ruby c.rb
Notice how "b loaded" is printed twice but if you replace require_relative with require it's just loaded once.
Shouldn't Ruby always expand the loaded files before appending them to the $LOADED_FEATURES and avoid this kind of error? I don't think require_relative should behave differently than a regular require in such cases.
Any thoughts?
Updated by abolshakov (Tema Bolshakov) over 8 years ago
- ruby -v changed from 2.1.2p95 to 2.3.1
Updated by abolshakov (Tema Bolshakov) over 8 years ago
- ruby -v changed from 2.3.1 to 2.3.1, 2.1.2p95
Updated by shyouhei (Shyouhei Urabe) over 8 years ago
- Subject changed from require_relative and require should be compatible with each other to require_relative and require should be compatible with each other when symlinks are used
Updated by nobu (Nobuyoshi Nakada) about 7 years ago
- Related to Bug #14372: Memory leak in require with Pathnames in the $LOAD_PATH in 2.3/2.4 added
Updated by nagachika (Tomoyuki Chikanaga) about 7 years ago
- Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.3: REQUIRED, 2.4: REQUIRED, 2.5: DONTNEED
Updated by nagachika (Tomoyuki Chikanaga) about 7 years ago
- Backport changed from 2.3: REQUIRED, 2.4: REQUIRED, 2.5: DONTNEED to 2.3: REQUIRED, 2.4: DONE, 2.5: DONTNEED
Updated by jeremyevans0 (Jeremy Evans) almost 6 years ago
- Has duplicate Bug #13695: Issue with require and require_relative with symlinked directories added
Updated by mame (Yusuke Endoh) about 4 years ago
- Related to Feature #16978: Ruby should not use realpath for __FILE__ added
Updated by shyouhei (Shyouhei Urabe) almost 4 years ago
- Has duplicate Bug #17885: require_relative and require should be compatible with each other when symlinked files are used added
ActionsLike0