Safer writing of gear registry to disk

Use atomic_write and fsync when writing the gear registry to disk.
Ensure correct permissions on gear registry file

Need to make sure the permissions are correct after the atomic write.
Fix gear registry file permissions during backup/restore
Merge pull request #4017 from ncdc/gear-registry-atomic-write-sync

Merged by openshift-bot