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
Hello Christophe,
Tuesday, July 26, 2011, 8:10:43 PM, you wrote:
cjff> The method "SpFileStream>>readingFromFilename" seems containing a bug:
IIRC SpFileStream is from the Sport compatibility library for different Smalltalks.
Janko Mivsek might be in the know, or you have to find out the maintainer. Maybe it even is Janko.
Cheers,
Herbert
Janko Mivsek might be in the know
I talked with him through IRC and he ask me to post the bug on the Squeak mailling list (I guess Sport is not big enough to have its own bug-tracker/mailling list)
Christophe.
----- Mail Original ----- De: "Herbert König" herbertkoenig@gmx.net À: "The general-purpose Squeak developers list" squeak-dev@lists.squeakfoundation.org Envoyé: Mardi 26 Juillet 2011 20h54:13 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne Objet: Re: [squeak-dev] Bug in SpFileStream>>readingFromFilename on read-only files
Hello Christophe,
Tuesday, July 26, 2011, 8:10:43 PM, you wrote:
cjff> The method "SpFileStream>>readingFromFilename" seems containing a bug:
IIRC SpFileStream is from the Sport compatibility library for different Smalltalks.
Janko Mivsek might be in the know, or you have to find out the maintainer. Maybe it even is Janko.
Cheers,
Herbert
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@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
squeak-dev@lists.squeakfoundation.org