On Wed, 31 Mar 2010, Andreas Raab wrote:
Hi -
I was just trying to implement the code for condensing the changes to the end of the sources file and ran into some 'interesting' issues. I would expect this to work:
fullName := 'test1.sources'. "Copy sources file; change file name accordingly" FileStream forceNewFileNamed: fullName do:[:newFile| sourcesFile := SourceFiles at: 1. sourcesFile position: 0. FileDirectory default copyFile: sourcesFile toFile: newFile. newFile position = sourcesFile size ifFalse:[self error: 'File copy failed']. ].
This one is definitely a bug. Using a readOnlyCopy instead of the original sources file makes debugging a bit easier. :)
But it fails. Then I tried something else:
fullName := 'test2.sources'. "Copy sources file; change file name accordingly" FileStream forceNewFileNamed: fullName do:[:newFile| sourcesFile := SourceFiles at: 1. sourcesFile position: 0. [sourcesFile atEnd] whileFalse:[newFile nextChunkPut: sourcesFile nextChunk]. newFile position = sourcesFile size ifFalse:[self error: 'File copy failed']. ].
That fails to. Then I tried:
fullName := 'test3.sources'. "Copy sources file; change file name accordingly" FileStream forceNewFileNamed: fullName do:[:newFile| sourcesFile := SourceFiles at: 1. sourcesFile position: 0. [sourcesFile atEnd] whileFalse:[newFile nextChunkPutWithStyle: sourcesFile nextChunkText]. newFile position = sourcesFile size ifFalse:[self error: 'File copy failed']. ].
That fails as well. Help! What am I doing wrong? How does one copy the sources file properly and why do the above methods not work?
The latter two will probably fail, since the chunk reading code throws away unnecessary whitespaces.
I checked these in 4.0 and all three are failing the same way as in 4.1.
Levente
Cheers,
- Andreas