From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [JGIT PATCH 2/2] index-pack: Use fsync to ensure received pack data is on disk
Date: Wed, 27 Aug 2008 14:48:44 -0700 [thread overview]
Message-ID: <1219873724-13348-2-git-send-email-spearce@spearce.org> (raw)
In-Reply-To: <1219873724-13348-1-git-send-email-spearce@spearce.org>
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>
---
.../src/org/spearce/jgit/transport/IndexPack.java | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java
index db9268e..7b1f7ee 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java
@@ -259,6 +259,8 @@ public void index(final ProgressMonitor progress) throws IOException {
fixThinPack(progress);
}
}
+ if (packOut != null)
+ packOut.getChannel().force(true);
packDigest = null;
baseById = null;
@@ -510,6 +512,7 @@ private void writeIdx() throws IOException {
else
iw = PackIndexWriter.createVersion(os, outputVersion);
iw.write(list, packcsum);
+ os.getChannel().force(true);
} finally {
os.close();
}
--
1.6.0.174.gd789c
next prev parent reply other threads:[~2008-08-27 21:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-27 21:48 [JGIT PATCH 1/2] index-pack: Avoid disk corruption yielding a valid pack footer checksum Shawn O. Pearce
2008-08-27 21:48 ` Shawn O. Pearce [this message]
2008-08-28 0:09 ` Nicolas Pitre
2008-08-28 0:14 ` Shawn O. Pearce
2008-08-28 0:26 ` Nicolas Pitre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1219873724-13348-2-git-send-email-spearce@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=robin.rosenberg@dewire.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).