Sync before rename, since the rename is not affected by the sync and doing it this way round means we can't expose the results of a half-written but renamed file by crashing after the rename but before the sync.
Merged bug25826 into stable