Correct replacing of log file

Do not leak resources in case of errors and ensure data is synced to
disk before replacing files.
fix(sync) leader should do a sync before committing log entires
As we do not fsync every time log writes to file when the state is leader, we need to do fsync before actually committing the log entries to ensure safety.
Save config file atomically
fix(util.go) make writeFileSynced return error properly
Merge pull request #150 from xiangli-cmu/sync_fix

Fix file issue