Bug #5859

incorrect return value of Pathname.realdirpath of Pathname objects created by Pathname.entries

Added by Thomas Green over 3 years ago. Updated over 3 years ago.

[ruby-core:41959]
Status:Closed
Priority:Low
Assignee:-
ruby -v:ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux] Backport:

Description

It appears when calling realdirpath on a Pathname object returned by Pathname#entries, the returned value is always the current working directory of the ruby process, instead of the location of the file in the filesystem
This disagrees with the rdoc description of Pathname#realdirpath, which does state that realdirpath will return the absolute name of the file.

Tho following code demonstrates the issue:

mkdir /tmp/thing
touch /tmp/thing/a
cd ~

ruby-1.9.3-p0 -ve "require 'pathname'; puts Pathname.new('/tmp/thing').entries.sort[2].realdirpath"

This is the output from the ruby process:

ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]

/home/t/a

According to my interpretation of the description in rdoc, the correct output should be "/tmp/thing/a"
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/pathname/rdoc/Pathname.html#method-i-realdirpath

Associated revisions

Revision 34246
Added by Akira Tanaka over 3 years ago

  • ext/pathname/pathname.c (path_entries): add document suggested by the thread [Bug #5859].

Revision 34246
Added by Akira Tanaka over 3 years ago

  • ext/pathname/pathname.c (path_entries): add document suggested by the thread [Bug #5859].

History

#1 Updated by Motohiro KOSAKI over 3 years ago

A following modified script tell us why the script don't work as you expect. Pathname#entries return directly entrie, not absolute path. then, it forgot /tmp/thing.

% ./ruby--trunk -e "require 'pathname'; p Pathname.new('/tmp/thing').entries.sort[2]"

#Pathname:a

It is not a bug. just misleading spec.

#2 Updated by Benoit Daloze over 3 years ago

I was going to answer but kosaki just did it.
Anyway, #entries always return filenames.
#children return what you would expect by default(with_directory=true):
ruby -e "require 'pathname'; puts Pathname.new('/tmp/thing').children.first.realdirpath" # => /tmp/thing/a

Although it would not work either if you used a relative path and chdir'd, in which case you should #expand_path before.

I think it would be worth to add an example to Pathname#entries and I'm unsure if such low-level method is useful at all in Pathname.

#3 Updated by Ayumu AIZAWA over 3 years ago

  • Priority changed from Normal to Low
  • Target version set to 2.0.0
  • Category set to doc

#4 Updated by Akira Tanaka over 3 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r34246.
Thomas, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • ext/pathname/pathname.c (path_entries): add document suggested by the thread [Bug #5859].

#5 Updated by Benoit Daloze over 3 years ago

Thank you Akira for improving the documentation.

I would have gladly helped as I made the suggestion, but I'm unfortunately pretty busy right now.

Also available in: Atom PDF