Project

General

Profile

Actions

Bug #10222

closed

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

Added by rosenfeld (Rodrigo Rosenfeld Rosas) over 9 years ago. Updated over 3 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 master - Bug #14372: Memory leak in require with Pathnames in the $LOAD_PATH in 2.3/2.4ClosedActions
Related to Ruby master - Feature #16978: Ruby should not use realpath for __FILE__Assignednobu (Nobuyoshi Nakada)Actions
Has duplicate Ruby master - Bug #13695: Issue with require and require_relative with symlinked directoriesClosedActions
Has duplicate Ruby master - Bug #17885: require_relative and require should be compatible with each other when symlinked files are usedClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0