Request/bug: Write to temp file in PNG Export
Migrated from: https://bugs.launchpad.net/inkscape/+bug/1771321
Steps to reproduce:
- open Inkscape
- open a sprite file (for testing, any file with an complex object will do, say a large image)
- export to png
- find the exported file in a file manager
- make sure image is large so it takes a bit to export (e.g. 8000px)
- export to png (overwrite the old file)
- observe the file is directly overwritten while it is being written.
What should have happened?
Inkscape should write to a temporary file and then move it to the desired location. (temp file should not be public, should not conflict with other files).
Use case as described by OP (ChrisDone on Launchpad):
This makes it impossible to use programs that e.g. watch for file modifications and refresh the image elsewhere when working with Inkscape. I'm making sprites in Inkscape for game dev, and I wrote a simple routine to refresh sprites when updated by Inkscape. But it always fails with "invalid PNG" because the file has not finished being written.
OP identified the relevant code in 0.92.x as from https://git.launchpad.net/inkscape/tree/src/helper/png-write.cpp?h=0.92.x#n143 to https://git.launchpad.net/inkscape/tree/src/helper/png-write.cpp?h=0.92.x#n293
They also offered to contribute a patch (posted on 2018-05-15)
Note: there is a similar issue with save as pdf and presumably every other save option, though this use case is specific to png exports.
Inkscape Version and Operating System:
- 1.0alpha (5e59ab6335, 2019-05-06, custom) build Linux Mint 19.1
- 0.92.4 (5095c1b47b, 2019-04-30) build Linux Mint 19.1
- 0.91+devel+osxmenu r12922, 2015
- 0.92.x build by OP, mentioned on 2018-05-15