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.
Atomic operations
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Atomic operations
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:
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/
https://imagemagick.org/Usage/