On Wed, Mar 22, 2017 at 01:50:45PM +0100, Karoly Balogh (Charlie/SGR) wrote:
> The usual way to work this problem around on Linux systems at least, is to
> write a new file, then do an overwriting rename to the old file name.
> There rename is an "atomic" operation, which will be either committed to
> the disk or not, but if it was unsuccessful, you won't end up with
> half-written files. But IIRC Windows didn't support atomic renames. Maybe
> someone with more Windows knowledge will fix me. You definitely don't want
> to implement a copy though, and that's anything but atomic.

I remember discussions about atomic rename for go and python (you can
still find the bug reports online).  The consensus seems to be that
MoveFileEx with MOVEFILE_REPLACE_EXISTING and MOVEFILE_WRITE_THROUGH
flags will be atomic if the file is on the same volume, and if that
volume supports changing the metadata in one transaction (which most do,
afaik).

MSDN recommends ReplaceFile() instead of TxF:

https://msdn.microsoft.com/en-us/library/windows/desktop/hh802690(v=vs.85).aspx

But I _think_ this is just a convenience function that uses
MoveFileEx().

So you can basically follow the same strategy as on POSIX, but with
MoveFileEx().

Henry
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to