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

Added by nobu (Nobuyoshi Nakada) over 7 years ago

Revision b6d3927e

load.c: real path to load

  • load.c (rb_construct_expanded_load_path): expand load paths to
    real paths to get rid of duplicate loading from symbolic-linked
    directories. [Feature #10222]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Added by nagachika (Tomoyuki Chikanaga) about 7 years ago

Revision eaba9da1

merge revision(s) 59983,59984: [Backport #10222] [Backport #14372] [Backport #14424]

    file.c: rb_check_realpath

    * file.c (rb_check_realpath): returns real path which has no
      symbolic links.  similar to rb_realpath except for returning
      Qnil if any parts did not exist.

    load.c: real path to load

    * load.c (rb_construct_expanded_load_path): expand load paths to
      real paths to get rid of duplicate loading from symbolic-linked
      directories.  [Feature #10222]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@62440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

ActionsLike0

Also available in: Atom PDF