Bug #7729

__dir__ returns a absolute dir path

Added by Narihiro Nakamura about 2 years ago. Updated about 2 years ago.

[ruby-core:51578]
Status:Rejected
Priority:Normal
Assignee:Narihiro Nakamura
ruby -v:ruby 2.0.0dev (2013-01-23 trunk 38552) [x86_64-linux] Backport:

Description

Hi.

dir returns a absolute dir path. It seems like a bug.

I've attached a patch.
mame-san, can I commit it to 2.0.0?

This issue is reported here: https://github.com/ruby/ruby/commit/805b08f2925f5ceec67bf472e76e869bbddc8c39#commitcomment-2474426

Thanks!

__dir__to_relative.rb Magnifier (1.34 KB) Narihiro Nakamura, 01/23/2013 01:54 PM


Related issues

Related to Ruby trunk - Feature #3346: __DIR__ revisted Closed 05/26/2010

Associated revisions

Revision 38915
Added by nari about 2 years ago

  • eval.c (f_current_dirname): Add documentation about "__dir__ returns always an absolute path". [Bug #7729]

Revision 38915
Added by nari about 2 years ago

  • eval.c (f_current_dirname): Add documentation about "__dir__ returns always an absolute path". [Bug #7729]

Revision 38916
Added by Yui NARUSE about 2 years ago

fix rdoc of dir [Bug #7729]

Revision 38916
Added by Yui NARUSE about 2 years ago

fix rdoc of dir [Bug #7729]

History

#1 Updated by Motohiro KOSAKI about 2 years ago

dir returns a absolute dir path. It seems like a bug.

Why?

+rb_current_relative_realfilepath(void)

A name of rb_current_realfilepath() seems to be derived from realpath(3) (i.e. imply absolute path and
resolved symlink). so, relative_realpath seems a bit strange to me.

#2 Updated by Shugo Maeda about 2 years ago

authorNari (Narihiro Nakamura) wrote:

dir returns a absolute dir path. It seems like a bug.

I doubt it.

Have you read the discussions in #3346?
I guess dir should return an absolute path in case the current directory is changed.

Do you have any reason to make dir return a relative path?

#3 Updated by Narihiro Nakamura about 2 years ago

shugo (Shugo Maeda) wrote:

authorNari (Narihiro Nakamura) wrote:

dir returns a absolute dir path. It seems like a bug.

I doubt it.

Have you read the discussions in #3346?
I guess dir should return an absolute path in case the current directory is changed.

Do you have any reason to make dir return a relative path?

File.dirname(__FILE__) returns a relative path. This is only my reason.
But your opinion is certainly true.
I agree dir returns an absolute path to keep the right location.

#4 Updated by Koichi Sasada about 2 years ago

(2013/01/23 23:31), authorNari (Narihiro Nakamura) wrote:

File.dirname(__FILE__) returns a relative path. This is only my reason.

$ cat t.rb
p [:__FILE__, FILE]
p [:__dir__, dir]
require './t'
$ ruby t.rb
#=>
[:__FILE__, "t.rb"]
[:__dir__, "c:/ko1/src/rb"]
[:__FILE__, "c:/ko1/src/rb/t.rb"]
[:__dir__, "c:/ko1/src/rb"]

Only the first script returns relative path by FILE.
I think all of FILE and dir should return absolute path.

# BTW, why it returns relative path?

--
// SASADA Koichi at atdot dot net

#5 Updated by Narihiro Nakamura about 2 years ago

  • Status changed from Open to Rejected

I've rejected this ticket, because I think it's not a bug.

ko1 (Koichi Sasada) wrote:

(2013/01/23 23:31), authorNari (Narihiro Nakamura) wrote:

File.dirname(__FILE__) returns a relative path. This is only my reason.

$ cat t.rb
p [:__FILE__, FILE]
p [:__dir__, dir]
require './t'
$ ruby t.rb
#=>
[:__FILE__, "t.rb"]
[:__dir__, "c:/ko1/src/rb"]
[:__FILE__, "c:/ko1/src/rb/t.rb"]
[:__dir__, "c:/ko1/src/rb"]

Only the first script returns relative path by FILE.
I think all of FILE and dir should return absolute path.

# BTW, why it returns relative path?

I see. Could you open a new ticket for this comment?

#6 Updated by Motohiro KOSAKI about 2 years ago

On Wed, Jan 23, 2013 at 10:19 PM, Shugo Maeda shugo@ruby-lang.org wrote:

2013/01/24 2:28 "SASADA Koichi" ko1@atdot.net:

Only the first script returns relative path by FILE.
I think all of FILE and dir should return absolute path.

BTW, why it returns relative path?

For code like $0 == FILE ?
How about to add file, which always returns an absolute path, maybe in
the next minor?

or how about overload '==' if given $0 and FILE?

Also available in: Atom PDF