Project

General

Profile

ActionsLike0

Bug #10222

closed

require_relative and require should be compatible with each other when symlinks are used

Added by rosenfeld (Rodrigo Rosenfeld Rosas) over 10 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
2.3.1, 2.1.2p95
[ruby-core:64928]

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?


Related issues 4 (1 open3 closed)

Related to Ruby - Bug #14372: Memory leak in require with Pathnames in the $LOAD_PATH in 2.3/2.4ClosedActions
Related to Ruby - Feature #16978: Ruby should not use realpath for __FILE__Assignednobu (Nobuyoshi Nakada)Actions
Has duplicate Ruby - Bug #13695: Issue with require and require_relative with symlinked directoriesClosedActions
Has duplicate Ruby - Bug #17885: require_relative and require should be compatible with each other when symlinked files are usedClosedActions

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
#15

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

  • Status changed from Open to Closed
#16

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
#17

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
#20

Updated by jeremyevans0 (Jeremy Evans) almost 6 years ago

  • Has duplicate Bug #13695: Issue with require and require_relative with symlinked directories added
#22

Updated by mame (Yusuke Endoh) about 4 years ago

  • Related to Feature #16978: Ruby should not use realpath for __FILE__ added
#23

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

Also available in: Atom PDF