file size primitive bug?

David T. Lewis lewis at mail.msen.com
Thu Feb 26 04:09:39 UTC 2004


On Wed, Feb 25, 2004 at 06:38:58PM -0800, Julian Fitzell wrote:
> I've encountered a problem, while using OmniBase, in that squeak returns 
> an incorrect file size if the size has changed since it was opened. 
> This appears to be because the file size is returned from a 
> rarely-updated file structure.  I have solved this by changing 
> sqFileSize() to get a file descriptor with "fileno(f->file)" and then 
> using fstat() to get the file size.
> 
> There are several other references to f->fileSize which I think could be 
> replaced with calls to the new and improved sqFileSize() (or this could 
> be pulled out into another helper I guess...
> 
> Does anyone see any reason why this shouldn't work this way?  Is it too 
> slow in some case or something?  I guess fstat() isn't ANSI-compliant... 
> how much does that matter compared to returning an incorrect value?
> 
> I guess my questions are two-fold:
> 
> 1) Is there some reason I shouldn't be doing this in my own VM?
> 2) Should I be preparing this to submit as a fix?
> 
> Julian

See DirectoryPlugin on Squeak Map, which provides a stat(2) call. Ian's
VM distribution includes the precompiled plugin, and if you load DirectoryPlugin
source from Squeak Map, there is an example class side method #stat that
does what you want. For example the size of file '/etc/hosts' is answered by:

	(DirectoryPlugin stat: '/etc/hosts') at: 5

or equivalently by:

	(DirectoryPlugin getEntry: '/etc/hosts') fileSize

I believe that this works correctly on Windows also, although it would be
inconvenient to reboot and confirm it right now ;-)

Dave




More information about the Squeak-dev mailing list