gammasoft/latex — pull request #6 by cscott (2014-07-31 19:04:13+00:00)
Title: Fix race after output file creation that can lead to EEXIST during cleanup

When node returns a file descriptor for a newly-opened file, it doesn't
necessarily mean that the file is present in its parent directory yet.

And note that `fsync(2)` states: "Calling fsync() does not necessarily
ensure that the entry in the directory containing the file has also
reached disk. For that an explicit fsync() on a file descriptor for
the directory is also needed."

Add appropriate calls to `fs.fsync`, both on the file and its
containing directory, to ensure that `rimraf` doesn't throw an
`EEXIST` by trying to remove the directory before the output
file is "present" in it.