Project

General

Profile

Actions

Bug #7729

closed

__dir__ returns a absolute dir path

Added by authorNari (Narihiro Nakamura) about 11 years ago. Updated about 11 years ago.

Status:
Rejected
Target version:
ruby -v:
ruby 2.0.0dev (2013-01-23 trunk 38552) [x86_64-linux]
Backport:
[ruby-core:51578]

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!


Files

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

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #3346: __DIR__ revistedClosedyhara (Yutaka HARA)05/26/2010Actions

Updated by kosaki (Motohiro KOSAKI) about 11 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.

Updated by shugo (Shugo Maeda) about 11 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?

Updated by authorNari (Narihiro Nakamura) about 11 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.

Updated by ko1 (Koichi Sasada) about 11 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

Updated by authorNari (Narihiro Nakamura) about 11 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?

Updated by kosaki (Motohiro KOSAKI) about 11 years ago

On Wed, Jan 23, 2013 at 10:19 PM, Shugo Maeda wrote:

2013/01/24 2:28 "SASADA Koichi" :

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?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0