Write the contents of the file with fwrite instead of g_file_set_contents. Since g_file_set_contents removes the file and re-creates it, all permissions get lost during this operation. Using fwrite preserves all the permissions.
Made changes according to review comments. Added a check if the FILE* is valid to prevent errors (there was a failing unit test).
convert error code for stream i/o on replace file call
Merge pull request #366 from adobe/irichter/fix-5533

Write the contents of the file with fwrite instead of g_file_set_contents