ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:64928] [ruby-trunk - Bug #10222] [Open] require_relative and require should be compatible with each other
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
@ 2014-09-10 12:53 ` rr.rosas
  2014-09-10 14:23 ` [ruby-core:64932] [ruby-trunk - Bug #10222] " rr.rosas
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: rr.rosas @ 2014-09-10 12:53 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been reported by Rodrigo Rosenfeld Rosas.

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other
https://bugs.ruby-lang.org/issues/10222

* Author: Rodrigo Rosenfeld Rosas
* Status: Open
* Priority: Normal
* Assignee: 
* Category: core
* Target version: 
* ruby -v: 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:64932] [ruby-trunk - Bug #10222] require_relative and require should be compatible with each other
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
  2014-09-10 12:53 ` [ruby-core:64928] [ruby-trunk - Bug #10222] [Open] require_relative and require should be compatible with each other rr.rosas
@ 2014-09-10 14:23 ` rr.rosas
  2014-09-14  9:56 ` [ruby-core:65031] " shevegen
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: rr.rosas @ 2014-09-10 14:23 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by Rodrigo Rosenfeld Rosas.


I can't change the title myself. Could someone with privileges please change it to something like: "require_relative and require should be compatible with each other when symlinks are used".

I think this would make it easier to be searchable if others are experiencing the same issue. The key change is to add the "symlinks" word to the title so that the connection is made clear.

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other
https://bugs.ruby-lang.org/issues/10222#change-48823

* Author: Rodrigo Rosenfeld Rosas
* Status: Open
* Priority: Normal
* Assignee: 
* Category: core
* Target version: 
* ruby -v: 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:65031] [ruby-trunk - Bug #10222] require_relative and require should be compatible with each other
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
  2014-09-10 12:53 ` [ruby-core:64928] [ruby-trunk - Bug #10222] [Open] require_relative and require should be compatible with each other rr.rosas
  2014-09-10 14:23 ` [ruby-core:64932] [ruby-trunk - Bug #10222] " rr.rosas
@ 2014-09-14  9:56 ` shevegen
  2016-08-19  6:58 ` [ruby-core:76978] [Ruby trunk Bug#10222] " tweekane
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: shevegen @ 2014-09-14  9:56 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by Robert A. Heiler.


Curious behaviour indeed, there may be a reason why symlinks were assumed to behave differently.

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other
https://bugs.ruby-lang.org/issues/10222#change-48898

* Author: Rodrigo Rosenfeld Rosas
* Status: Open
* Priority: Normal
* Assignee: 
* Category: core
* Target version: 
* ruby -v: 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:76978] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2014-09-14  9:56 ` [ruby-core:65031] " shevegen
@ 2016-08-19  6:58 ` tweekane
  2016-08-19  6:59 ` [ruby-core:76979] " tweekane
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: tweekane @ 2016-08-19  6:58 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by Tema Bolshakov.

ruby -v changed from 2.1.2p95 to 2.3.1

The issue is reproduced on ruby 2.3.1

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other
https://bugs.ruby-lang.org/issues/10222#change-60203

* Author: Rodrigo Rosenfeld Rosas
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.1
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:76979] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2016-08-19  6:58 ` [ruby-core:76978] [Ruby trunk Bug#10222] " tweekane
@ 2016-08-19  6:59 ` tweekane
  2016-10-11 11:07 ` [ruby-core:77573] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used shyouhei
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: tweekane @ 2016-08-19  6:59 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by Tema Bolshakov.

ruby -v changed from 2.3.1 to 2.3.1, 2.1.2p95

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other
https://bugs.ruby-lang.org/issues/10222#change-60204

* Author: Rodrigo Rosenfeld Rosas
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.1, 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:77573] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2016-08-19  6:59 ` [ruby-core:76979] " tweekane
@ 2016-10-11 11:07 ` shyouhei
  2016-10-11 13:19 ` [ruby-core:77581] " rr.rosas
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: shyouhei @ 2016-10-11 11:07 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by Shyouhei Urabe.

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

We looked at this issue in developer meeting today.

The ultimate reason why require and require_relative behaves differently is that while require_relative infers its argument's realpath every time, require doesn't.

This _was_ by design; because require is called many times, we wanted to completely avoid disk access for 2nd and later calls to require with identical arguments.

But I believe the reported behaviour is a bug to be fixed.  In order to do so a meeting attendee suggested to push both symlink-resolved and unresolved paths at once to $LOADED_FEATURES on the first call.


----------------------------------------
Bug #10222: require_relative and require should be compatible with each other when symlinks are used
https://bugs.ruby-lang.org/issues/10222#change-60844

* Author: Rodrigo Rosenfeld Rosas
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.1, 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:77581] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2016-10-11 11:07 ` [ruby-core:77573] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used shyouhei
@ 2016-10-11 13:19 ` rr.rosas
  2016-10-11 15:39 ` [ruby-core:77584] " nobu
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: rr.rosas @ 2016-10-11 13:19 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by Rodrigo Rosenfeld Rosas.


This could make it harder for auto-reloaders to unload a required file when require_relative is used... Doesn't seem like a great solution to this bug to me... Ruby could cache internally the real path when using "require" so that the second call would avoid any disk access...

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other when symlinks are used
https://bugs.ruby-lang.org/issues/10222#change-60852

* Author: Rodrigo Rosenfeld Rosas
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.1, 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:77584] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2016-10-11 13:19 ` [ruby-core:77581] " rr.rosas
@ 2016-10-11 15:39 ` nobu
  2016-10-11 17:13 ` [ruby-core:77587] " rr.rosas
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: nobu @ 2016-10-11 15:39 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by Nobuyoshi Nakada.


Shyouhei Urabe wrote:
> In order to do so a meeting attendee suggested to push both symlink-resolved and unresolved paths at once to `$LOADED_FEATURES` on the first call.

I think this explanation differs from that we discussed accurately.
IIRC, it should be `vm->expanded_load_path`, not `$LOADED_FEATURES`.
`$LOADED_FEATURES` won't be doubled, but will have realpaths only.




----------------------------------------
Bug #10222: require_relative and require should be compatible with each other when symlinks are used
https://bugs.ruby-lang.org/issues/10222#change-60855

* Author: Rodrigo Rosenfeld Rosas
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.1, 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:77587] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2016-10-11 15:39 ` [ruby-core:77584] " nobu
@ 2016-10-11 17:13 ` rr.rosas
  2016-11-01  6:44 ` [ruby-core:77849] " shyouhei
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: rr.rosas @ 2016-10-11 17:13 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by Rodrigo Rosenfeld Rosas.


Nobu, if a symlinked path would be removed from $LOADED_FEATURES from Ruby code, will all related internal references to the same file be cleared too?

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other when symlinks are used
https://bugs.ruby-lang.org/issues/10222#change-60857

* Author: Rodrigo Rosenfeld Rosas
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.1, 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:77849] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2016-10-11 17:13 ` [ruby-core:77587] " rr.rosas
@ 2016-11-01  6:44 ` shyouhei
  2017-09-13 14:45 ` [ruby-core:82773] " nobu
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: shyouhei @ 2016-11-01  6:44 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by Shyouhei Urabe.


Today I learned that [PHP caches realpath](http://jpauli.github.io/2014/06/30/realpath-cache.html), and causes troubles when people use symlink to deploy scripts.

The situation is not exactly the identical to ours, but we should avoid their footsteps.

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other when symlinks are used
https://bugs.ruby-lang.org/issues/10222#change-61161

* Author: Rodrigo Rosenfeld Rosas
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.1, 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:82773] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2016-11-01  6:44 ` [ruby-core:77849] " shyouhei
@ 2017-09-13 14:45 ` nobu
  2017-09-13 15:27 ` [ruby-core:82774] " rr.rosas
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: nobu @ 2017-09-13 14:45 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by nobu (Nobuyoshi Nakada).


Would you expect just directory names get expanded?
Or basename too?
For instance, 'b loaded' should be printed twice or just once,?

```
mkdir a
echo "p 'b loaded'" > a/b.rb
ln -s b.rb a/c.rb
ruby -I./a -ra -rb -e''
```

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other when symlinks are used
https://bugs.ruby-lang.org/issues/10222#change-66629

* Author: rosenfeld (Rodrigo Rosenfeld Rosas)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.1, 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:82774] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2017-09-13 14:45 ` [ruby-core:82773] " nobu
@ 2017-09-13 15:27 ` rr.rosas
  2017-09-13 15:29 ` [ruby-core:82775] " rr.rosas
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: rr.rosas @ 2017-09-13 15:27 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).


I'd expect b.rb and c.rb to be handled like separate files, so "b loaded" would be printed twice.

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other when symlinks are used
https://bugs.ruby-lang.org/issues/10222#change-66630

* Author: rosenfeld (Rodrigo Rosenfeld Rosas)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.1, 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:82775] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2017-09-13 15:27 ` [ruby-core:82774] " rr.rosas
@ 2017-09-13 15:29 ` rr.rosas
  2017-09-13 23:35 ` [ruby-core:82776] " ronnie
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: rr.rosas @ 2017-09-13 15:29 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).


I see, what you mean, if we simply add the expanded filenames to LOADED_PATH then that file would be loaded just once. Do you have any use cases where someone would symlink Ruby code for good usage?

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other when symlinks are used
https://bugs.ruby-lang.org/issues/10222#change-66631

* Author: rosenfeld (Rodrigo Rosenfeld Rosas)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.1, 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:82776] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
                   ` (12 preceding siblings ...)
  2017-09-13 15:29 ` [ruby-core:82775] " rr.rosas
@ 2017-09-13 23:35 ` ronnie
  2017-09-13 23:38 ` [ruby-core:82777] " rr.rosas
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 17+ messages in thread
From: ronnie @ 2017-09-13 23:35 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by matsuda (Akira Matsuda).


Here's an actual use case that we saw in Rails: https://github.com/rails/rails/pull/29638#issuecomment-321335175
The reporter says that it happened in Jenkins, but I guess the same situation may happen in any case where we put the .rb files under a symlinked directory, for instance Capistrano.

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other when symlinks are used
https://bugs.ruby-lang.org/issues/10222#change-66633

* Author: rosenfeld (Rodrigo Rosenfeld Rosas)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.1, 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:82777] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
                   ` (13 preceding siblings ...)
  2017-09-13 23:35 ` [ruby-core:82776] " ronnie
@ 2017-09-13 23:38 ` rr.rosas
  2018-01-31  4:26 ` [ruby-core:85275] " nagachika00
  2018-02-16 16:25 ` [ruby-core:85606] " nagachika00
  16 siblings, 0 replies; 17+ messages in thread
From: rr.rosas @ 2017-09-13 23:38 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).


Akira, in those cases was the basename different among the real path and the symlink?

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other when symlinks are used
https://bugs.ruby-lang.org/issues/10222#change-66634

* Author: rosenfeld (Rodrigo Rosenfeld Rosas)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.1, 2.1.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:85275] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
                   ` (14 preceding siblings ...)
  2017-09-13 23:38 ` [ruby-core:82777] " rr.rosas
@ 2018-01-31  4:26 ` nagachika00
  2018-02-16 16:25 ` [ruby-core:85606] " nagachika00
  16 siblings, 0 replies; 17+ messages in thread
From: nagachika00 @ 2018-01-31  4:26 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by nagachika (Tomoyuki Chikanaga).


I've filled Backport field according to the request at #14424.

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other when symlinks are used
https://bugs.ruby-lang.org/issues/10222#change-70043

* Author: rosenfeld (Rodrigo Rosenfeld Rosas)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.1, 2.1.2p95
* Backport: 2.3: REQUIRED, 2.4: REQUIRED, 2.5: DONTNEED
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [ruby-core:85606] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used
       [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
                   ` (15 preceding siblings ...)
  2018-01-31  4:26 ` [ruby-core:85275] " nagachika00
@ 2018-02-16 16:25 ` nagachika00
  16 siblings, 0 replies; 17+ messages in thread
From: nagachika00 @ 2018-02-16 16:25 UTC (permalink / raw
  To: ruby-core

Issue #10222 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.3: REQUIRED, 2.4: REQUIRED, 2.5: DONTNEED to 2.3: REQUIRED, 2.4: DONE, 2.5: DONTNEED

ruby_2_4 r62440 merged revision(s) 59983,59984.

----------------------------------------
Bug #10222: require_relative and require should be compatible with each other when symlinks are used
https://bugs.ruby-lang.org/issues/10222#change-70402

* Author: rosenfeld (Rodrigo Rosenfeld Rosas)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.1, 2.1.2p95
* Backport: 2.3: REQUIRED, 2.4: DONE, 2.5: DONTNEED
----------------------------------------
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?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2018-02-16 16:25 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-10222.20140910125348@ruby-lang.org>
2014-09-10 12:53 ` [ruby-core:64928] [ruby-trunk - Bug #10222] [Open] require_relative and require should be compatible with each other rr.rosas
2014-09-10 14:23 ` [ruby-core:64932] [ruby-trunk - Bug #10222] " rr.rosas
2014-09-14  9:56 ` [ruby-core:65031] " shevegen
2016-08-19  6:58 ` [ruby-core:76978] [Ruby trunk Bug#10222] " tweekane
2016-08-19  6:59 ` [ruby-core:76979] " tweekane
2016-10-11 11:07 ` [ruby-core:77573] [Ruby trunk Bug#10222] require_relative and require should be compatible with each other when symlinks are used shyouhei
2016-10-11 13:19 ` [ruby-core:77581] " rr.rosas
2016-10-11 15:39 ` [ruby-core:77584] " nobu
2016-10-11 17:13 ` [ruby-core:77587] " rr.rosas
2016-11-01  6:44 ` [ruby-core:77849] " shyouhei
2017-09-13 14:45 ` [ruby-core:82773] " nobu
2017-09-13 15:27 ` [ruby-core:82774] " rr.rosas
2017-09-13 15:29 ` [ruby-core:82775] " rr.rosas
2017-09-13 23:35 ` [ruby-core:82776] " ronnie
2017-09-13 23:38 ` [ruby-core:82777] " rr.rosas
2018-01-31  4:26 ` [ruby-core:85275] " nagachika00
2018-02-16 16:25 ` [ruby-core:85606] " nagachika00

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).