Atomic operations

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
porton
Posts: 5
Joined: 2008-10-04T07:37:42-07:00

Atomic operations

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Atomic operations

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply