[squeak-dev] Bug in SpFileStream>>readingFromFilename on read-only files

christophe.jalady at free.fr christophe.jalady at free.fr
Tue Jul 26 18:10:43 UTC 2011


The method "SpFileStream>>readingFromFilename" seems containing a bug:

According to the name, this method should be able to read read-only files, but it does not.
The reason is because it use under the hood "FileStream>>oldFileNamed:" which try to open the file in read/write mode, and so fail on read-only files:
SpFileStream>>readingFromFilename: aSpFilename 
	...
        underlyingStream := FileStream oldFileNamed: self filename asString.
	...
	^self

A way to correct this is to apply this patch:
SpFileStream>>readingFromFilename: aSpFilename 
	self filename: aSpFilename.
        "WRONG: underlyingStream := FileStream oldFileNamed: self filename asString."
	underlyingStream := FileStream readOnlyFileNamed: self filename asString.
	^self


To reproduce the problem just evaluate the code below: the "underlyingStream" of the 'stream' is nil because it fail to open the file (make sure that '/usr/share/icons/hicolor/48x48/apps/gnome-mines.png' cannot be opened in read/write):
| stream aFilename|
	aFilename := SpFilename named: '/usr/share/icons/hicolor/48x48/apps/gnome-mines.png'.
	stream := aFilename readStream.
	^[
		stream binary.
		stream upToEnd ]
		ensure: [ stream close ]


Note: I wrongly created a bug entry in Seaside bug-tracker ( http://code.google.com/p/seaside/issues/detail?id=664 )

Christophe



More information about the Squeak-dev mailing list