Sync engine: Do not write to the database too early

It is possible that we have should_update_etag set to true for files
that we also need to propagate.  In which case we must not write to the DB
too early as this could cause data loss.  (cf: issue #2296)
Sync engine:  Restart sync when we get a precondition failed error