Project

General

Profile

Actions

Bug #13695

closed

Issue with require and require_relative with symlinked directories

Added by fidothe (Matt Patterson) almost 7 years ago. Updated almost 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
[ruby-core:81819]

Description

Symlinked directories cause an issue with require_relative where libraries loaded from a symlinked path (e.g. in a typical Capistrano / Bundler deployment) can be double-loaded.

Reproduce process:

  1. Clone git repo from https://github.com/fidothe/symlink-require
  2. Run use-symlink.rb script:
$ ruby use-symlink.rb

Expected result: No warning from double-loading of constants issued.
Actual result: double-loading of file causing already-initialised constant warning.

In the example I linked above, target.rb uses require_relative to load dependent.rb.

When the example also requires dependent.rb the file is double-loaded and we see a warning about already-initialized constant.

The problem is that when require in use-symlink.rb (line 7) checks the set of loaded files it uses an absolute path containing the symlink (since that is what was added to $LOAD_PATH), but when require_relative in target.rb is called, it uses an absolute path containing target of the symlink, causing the double-load.

Is this discrepancy intended behaviour on Ruby's part?


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #10222: require_relative and require should be compatible with each other when symlinks are usedClosedActions

Updated by rrosenblum (Ryan Rosenblum) almost 7 years ago

rspec-duplicate-require shows that this behavior has been around for at least 4 years. More recent discussions of this have been going on in prawn and pdf-core.

Updated by shyouhei (Shyouhei Urabe) almost 7 years ago

I guess this is a dup of #10222.

Updated by fidothe (Matt Patterson) almost 7 years ago

shyouhei (Shyouhei Urabe) wrote:

I guess this is a dup of #10222.

It is, sorry for not finding that when I looked for existing issues related to this.

Actions #4

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

  • Is duplicate of Bug #10222: require_relative and require should be compatible with each other when symlinks are used added
Actions #5

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0