Atomicity of file-copying/moving

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 17 13:14:39 PDT 2017


On Wed, May 17, 2017 at 07:56:52PM +0000, Per Nordlöw via Digitalmars-d-learn wrote:
> On Tuesday, 16 May 2017 at 10:57:08 UTC, FreeSlave wrote:
> > 
> > Not sure about renaming but copying is not atomic on Posix because
> > it does not handle interruption by signal. I opened issue about that
> > https://issues.dlang.org/show_bug.cgi?id=17296
> 
> The standard way is to copy the source to a temporary file on the same
> file system as the target file followed by hardlinking the temporary
> to the target file. If an error occurs during copying you either retry
> or abort.  That should be atomic.

Unfortunately it does suffer from the limitation that if the file is
large, you may run out of space on the target filesystem where you may
not have, had you overwritten the target file directly.  But I suppose
it's an acceptable tradeoff where atomicity of copying is desired.


T

-- 
"The number you have dialed is imaginary. Please rotate your phone 90 degrees and try again."


More information about the Digitalmars-d-learn mailing list