Hi Folks,
A Cuis user, Nicola Mingotti, in some app specific code, needed to read stuff from a file while some other process writes to it. This Squeak snippet simulates what he did, and a problem I found:
StandardFileStream forceNewFileNamed: 'test.txt' do: [ :fs | ]. reader := StandardFileStream fileNamed: 'test.txt'. Transcript cr; print: reader atEnd. StandardFileStream fileNamed: 'test.txt' do: [ :fs | fs nextPutAll: 'stuff']. Transcript cr; print: reader atEnd. reader close. Transcript cr; flush
This is the equivalent code for Cuis.
path := 'test.txt'. path asFileEntry fileContents: ''. fs := path asFileEntry readStream . fs atEnd print. path asFileEntry appendContents: 'stuff'. fs atEnd print. nil
Evaluating any of these, in Windows I get printed 'true' then 'false', the correct answer.
But on Ubuntu and MacOS, I get 'true' then 'true'.
If I modify #atEnd not to call #primAtEnd:
atEnd "Answer whether the receiver is at its end." collection ifNotNil: [ position < readLimit ifTrue: [ ^false ] ]. "^self primAtEnd: fileID" ^self position = self size
I get the correct answer in all three platforms.
This is a bug in the primitive, right?
Thanks,
vm-dev@lists.squeakfoundation.org