index-pack: Use fsync to ensure received pack data is on disk
C Git uses fsync() to ensure that a pack file is stable on disk before
it starts to delete any other copies of the data, or before it tries
to update refs to refer to data stored in the pack. This makes it a
lot less likely that a repository will see corruption due to refs
pointing at unavailable objects.
We now force our pack and its associated .idx file to disk before
we close the file descriptors, but after we have finished reading
and writing all of the data. This way we can be fairly certain
a future user of the data (like a RefUpdate) always has objects.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>