The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
File::Stat annoyances

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
File::Stat annoyances Posted: Jan 9, 2007 12:21 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: File::Stat annoyances
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
I need to stop looking at the Ruby source code, I really do. Because, you see, today I discovered what a mess the File::Stat class is. Oh, it works (though I discovered an issue today), but it goes through a lot of contortions for what ought to be a dead simple class.

When you call File::Stat.new, the attributes of that object are unaffected by further modifications to the file after the call. Ok, no problem. So, why is the stat buf being stored as an opaque data structure? Why not just call stat() within the File::Stat#initialize method, and set all the instance variables there? As it stands now, each File::Stat attribute is, in fact, a separate method call that has to grab the opaque data structure first, get the proper field, and convert it to a VALUE. Dumb.

The issue that I discovered today is that File.stat returns bogus values for attributes like 'size' and 'blksize' for character or block devices. Actually, scratch that. The proper behavior is muddled because the documentation doesn't agree with the implementation as far as what the stat() function should return for character and block devices, depending on your platform. Rich Teer's Solaris System's Programming (p. 357, if you must know) states that members like st_size and st_blksize are undefined on Solaris for character and block devices, but this doesn't appear to be the case in practice. The st_size member appears to get set to INT_MAX, while the st_blksize member value looks legit. Linux, on the other hand, actually does set the st_size member to NULL, but it still sets the st_blksize member.

So, where does this leave us? I suppose, for st_size at least, we'll have to add an explicit check for block and character devices, and set the size to 0 manually. I'm not sure about the rest of the fields. I'm going to tread into comp.unix.solaris and see what they have to say on the subject.

Read: File::Stat annoyances

Topic: Ruby On Rails IntelliSense Previous Topic   Next Topic Topic: 5 Things a Ruby developer needs to know about Scala

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use