At least write to a temp file(in the same filesystem), fsync the file and its folder and rename it over the original.