On 3/31/2010 3:59 PM, Levente Uzonyi wrote:
Okay, found the cause of the issue. MultiByteFileStream doesn't implement it's own version of #nextInto: which is used by #copyFile:toFile:, therefore the file is not decoded. Replacing #nextInto: with an appropriate #next: send passes the test.
Thanks for the help, I've worked around the problem by using #next: and #nextPutAll: which seems to work. It's yucky though; if I hadn't added my sanity test I wouldn't even have found the problem and the sources file would've been silently broken.
Cheers, - Andreas
Implementing MultiByteFileStream >> #nextInto: is a bit tricky, since if the argument is a ByteString, then there's a chance that the result cannot be stored into the buffer. In similar cases the ByteString is swapped with a WideString, but in this case it can become a source of bugs, since the sender of #nextInto: may expect that the buffer is still a ByteString.
IMHO #copyFile:toFile: shouldn't exist, it's just a utility method, totally unrelated to FileDirectory. It also assumes that the files are in "ascii" mode which is wrong.
Levente
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