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

Janko Mivšek janko.mivsek at eranova.si
Wed Jul 27 10:39:48 UTC 2011


Bonjour Christophe,

Thanks a lot for your patch, I'll integrate it into Sport as soon as
possible. In the meantime, can you add or adapt SUnit tests too? Some
additional test would be welcome to cover just your case. We would
really appreciate your contribution here!

Tests are in SportDev package, see http://www.squeaksource.com/SPort.html

Thanks again and best regards
Janko

S, christophe.jalady at free.fr piše:
> 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
> 
> 

-- 
Janko Mivšek
Aida/Web
Smalltalk Web Application Server
http://www.aidaweb.si



More information about the Squeak-dev mailing list