fsync the parent directory when fsyncing a new file
Don’t forget:
You should call
fsync
on the parent directory — that is, the directory containing your file — when you need to ensure that a newly-created file is fully synchronized back to disk. In that situation, you would callfsync
on both your file and its parent directory.
— Robert Love in response to When should you fsync the containing directory in addition to the file itself? on Quora.