Page 1 of 1

Atomic operations

Posted: 2011-12-08T08:49:38-07:00
by porton
Can ImageMagick be used in such a way that it will overwrite files atomically? That is I don't want a file be half-written at any stage of creating a new version of the file.

I use PerlMagick, but think that this my question is common for all ImageMagick interfaces.

Re: Atomic operations

Posted: 2011-12-11T23:00:50-07:00
by anthony
Atomic operations can only be performed by the system, and very much depends on the OS.

One way that generally works is to write the image to a new file in the same directory. The file is typically kept hidden (such as using a '.' at the start of the file name for UNIX systems). When done you simply 'move' the file
to generate a atomic filesystem rename to replace the original file in that directory. The filesystem will then clean up the old file automatically.

EG:

Code: Select all

    convert old_file.png   ...  .new_file.png
    mv .new_file.png old_file.png