summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cdf222f)
raw | patch | inline | side by side (parent: cdf222f)
author | Linus Torvalds <torvalds@linux-foundation.org> | |
Wed, 11 Jun 2008 01:47:18 +0000 (18:47 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 11 Jun 2008 05:23:18 +0000 (22:23 -0700) |
This consolidates the common operations for closing the new temporary file
that we have written, before we move it into place with the final name.
There's some common code there (make it read-only and check for errors on
close), but more importantly, this also gives a single place to add an
fsync_or_die() call if we want to add a safe mode.
This was triggered due to Denis Bueno apparently twice being able to
corrupt his git repository on OS X due to an unlucky combination of kernel
crashes and a not-very-robust filesystem.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
that we have written, before we move it into place with the final name.
There's some common code there (make it read-only and check for errors on
close), but more importantly, this also gives a single place to add an
fsync_or_die() call if we want to add a safe mode.
This was triggered due to Denis Bueno apparently twice being able to
corrupt his git repository on OS X due to an unlucky combination of kernel
crashes and a not-very-robust filesystem.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha1_file.c | patch | blob | history |
diff --git a/sha1_file.c b/sha1_file.c
index adcf37c3f68d16200b01adae441fa3d8f68e3c02..f311c79e50bce4cf39cd1c2c51f63974517a2f5c 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
return 0;
}
+/* Finalize a file on disk, and close it. */
+static void close_sha1_file(int fd)
+{
+ /* For safe-mode, we could fsync_or_die(fd, "sha1 file") here */
+ fchmod(fd, 0444);
+ if (close(fd) != 0)
+ die("unable to write sha1 file");
+}
+
static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
void *buf, unsigned long len, time_t mtime)
{
@@ -2170,9 +2179,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
if (write_buffer(fd, compressed, size) < 0)
die("unable to write sha1 file");
- fchmod(fd, 0444);
- if (close(fd))
- die("unable to write sha1 file");
+ close_sha1_file(fd);
free(compressed);
if (mtime) {
} while (1);
inflateEnd(&stream);
- fchmod(local, 0444);
- if (close(local) != 0)
- die("unable to write sha1 file");
+ close_sha1_file(local);
SHA1_Final(real_sha1, &c);
if (ret != Z_STREAM_END) {
unlink(tmpfile);