Bug #4563
closedDir#tell broken
Description
=begin
Dir#tell is not returning the correct value after a read:
dir = Dir.new(Dir.pwd)
p dir.tell # => 0
dir.read
p dir.tell # => 56334832
=end
Updated by nobu (Nobuyoshi Nakada) about 12 years ago
- Status changed from Open to Rejected
=begin
What's "the correct value" you think?
=end
Updated by djberg96 (Daniel Berger) about 12 years ago
=begin
I was expecting "1", in part because of the example from the pickaxe, and also because that's what JRuby returns. OS X 10.4 returns a simple index, too. However, I now see it's not necessarily just a simple index, depending on the platform.
=end
Updated by zenspider (Ryan Davis) about 12 years ago
- ruby -v changed from ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-linux] to -
=begin
On Apr 7, 2011, at 17:40 , Nobuyoshi Nakada wrote:
Issue #4563 has been updated by Nobuyoshi Nakada.
Status changed from Open to Rejected
What's "the correct value" you think?
Bug #4563: Dir#tell broken
http://redmine.ruby-lang.org/issues/4563Author: Daniel Berger
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-linux]Dir#tell is not returning the correct value after a read:
dir = Dir.new(Dir.pwd)
p dir.tell # => 0
dir.read
p dir.tell # => 56334832
fwiw, seems sane on osx:
dir = Dir.new(Dir.pwd)
=> #Dir:/Users/ryan
dir.tell
=> 0
dir.read
=> "."
dir.tell
=> 1
If I had to guess, maybe Dan is seeing the inode# ?
=end
Updated by normalperson (Eric Wong) about 12 years ago
=begin
Daniel Berger redmine@ruby-lang.org wrote:
I was expecting "1", in part because of the example from the pickaxe,
and also because that's what JRuby returns. OS X 10.4 returns a simple
index, too. However, I now see it's not necessarily just a simple
index, depending on the platform.
Yes, readdir/telldir aren't guaranteed to have any ordering. ext3
created with dir_index and ext4 (I think) do this to you, maybe others.
You can search for the spd_readdir LD_PRELOAD from Ted T'so
to get readdir() to sort by inode like you'd expect. spd_readdir
can reduce disk seeks if you're iterating through a directory, too.
--
Eric Wong
=end
Updated by djberg96 (Daniel Berger) about 12 years ago
=begin
On Fri, Apr 8, 2011 at 12:29 AM, Eric Wong normalperson@yhbt.net wrote:
Daniel Berger redmine@ruby-lang.org wrote:
I was expecting "1", in part because of the example from the pickaxe,
and also because that's what JRuby returns. OS X 10.4 returns a simple
index, too. However, I now see it's not necessarily just a simple
index, depending on the platform.Yes, readdir/telldir aren't guaranteed to have any ordering. Â ext3
created with dir_index and ext4 (I think) do this to you, maybe others.You can search for the spd_readdir LD_PRELOAD from Ted T'so
to get readdir() to sort by inode like you'd expect. Â spd_readdir
can reduce disk seeks if you're iterating through a directory, too.
Unfortunately that would create a dependency on a 3rd party library. I
think it would be nicer to just store the values in an internal array,
and reference that array, instead of the "real" result of Dir#tell.
This would mean modifying Dir#seek as well, but it would certainly be
a nicer interface for people, as I could use Dir#seek to an expected
specific point instead of storing and retrieving the results of
Dir#tell and messing with that. I'm guessing that's what JRuby (or
perhaps Java) is doing.
But, whatever. It's not a huge deal. Just mulling it around. :)
Regards,
Dan
=end