Sync pack data more carefully when writing
Sync pack data more carefully when writing

Otherwise a system failure might leave a broken repo.  Note that these
changes may not be comprehensive, but they're a start, and hopefully
deal with some of the most critical data.

In addition to syncing the pack data itself, sync the parent directory
after the final rename so that we don't risk losing the reference to
the new file.

See also:

  http://austingroupbugs.net/view.php?id=672
  https://www.sqlite.org/atomiccommit.html

Signed-off-by: Rob Browning <1dc5917c2adeeba13d1ef33dbb40691a1b67cc65@defaultvalue.org>
Tested-by: Rob Browning <1dc5917c2adeeba13d1ef33dbb40691a1b67cc65@defaultvalue.org>

ToxicFrog/bup,ToxicFrog/bup,gevaerts/bup,gevaerts/bup,ToxicFrog/bup,gevaerts/bup,ToxicFrog/bup,ToxicFrog/bup,gevaerts/bup,gevaerts/bup