[fpc-pascal] FreePascal Windows - Force files to write to disk
Giuliano Colla
giuliano.colla at fastwebnet.it
Wed Mar 22 18:52:14 CET 2017
Il 22/03/2017 14:21, Karoly Balogh (Charlie/SGR) ha scritto:
> Hi,
>
> On Wed, 22 Mar 2017, Giuliano Colla wrote:
>
>> Il 22/03/2017 13:20, James Richters ha scritto:
>>> No, it is not only freepascal, but not every program either.
>> A wild guess. The vilain could be the journal logic.
> Wild indeed. :)
>
>> You might try overwriting the old file instead of clearing it. Something
>> like:
>>
>> Assign.
>> Seek to the beginning of the file. (instead of rewrite)
>> Write whatever you need.
>> Truncate.
>> Close.
>>
>> This will give the journal a different story to cope with. Maybe it will
>> help.
> Even if this would work (no idea), it builds completely on assumptions and
> the behavior might be different depending on the underlying storage
> system. It's not atomic as well, because if you get a power loss during
> the above process, you could still end up with a broken file with random
> contents. So it is dangerous, and could be very hard to reproduce if it
> causes problems.
>
> See my other mails about the documented way, and what Microsoft seem to
> suggest.
There's no doubt that the best solution would be writing a new file and
then renaming it, second only to using an UPS to protect against
accidental power loss, which costs just a fraction of the time value
spent in this discussion.
My suggestion was just a test to get an idea on how the MS Journaling
works, and which pitfalls it may hide. If they store/execute the pending
operations not in the order they where given, but giving somehow
precedence to the operations faster to execute, and dropping the actions
which are no more executable, you might end up with a renamed file which
is still empty, because its creation and renaming are by far much faster
than writing it!
As far as Microsoft's suggestion are related, a friend of mine with some
decades of career as a MCSE once told me is that, according his
experience, the best course to take is always *not* to follow Microsofts
suggestions, but to do exactly the opposite....:-)
Giuliano
More information about the fpc-pascal
mailing list