[squeak-dev] Copying the sources file
Levente Uzonyi
leves at elte.hu
Wed Mar 31 22:59:15 UTC 2010
On Wed, 31 Mar 2010, Levente Uzonyi wrote:
> 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. :)
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.
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
>>
>>
>
>
More information about the Squeak-dev
mailing list
|