git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Potential problem in git-add may corrupt the index file

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 24, 2012, 01:51 UTC
Message-ID
<xmqq4ns9j3rf.fsf@junio.mtv.corp.google.com>
In-Reply-To
<CAEJt7hYYJh5dT1Tk99Oze6Hg4QaOqX5ERi0faWjyifQ6dr-pWw@mail.gmail.com>
Gang Hu <ganghu@cs.columbia.edu> writes:
> If a crash happens after the rename(), the data may have not been
> completely flushed into the index file, so the user may face an empty
> or corrupted index file.

Yeah, probably we should add fsync_or_die() at the end of write_index() in read-cache.c, possibly protect it with fsync_object_files just like we do in close_sha1_file() in sha1_file.c for loose object files.

I think the real fix would be to update the write_index() codepath to use the csum-file API, though. Then sha1close() will give us the fsync behaviour for free.

Previous: Gang HuNext: Gang Hu
Message 2 of 3 in “Potential problem in git-add may corrupt the index file”
  1. Gang HuApr 23, 2012
  2. Junio C HamanoApr 24, 2012
  3. Gang HuApr 29, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.