Another thing, the temp file this way is created in a temporary directory that might be "far away" from the data dir (as in, different mount, different file system) which would make the atomic rename impossible on Linux as well. Better use the 3 params version that allows to file to be created in the same directory as the target file