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

Re: Consolidate SHA1 object file close

From
Andreas Ericsson <ae@op5.se>
Date
Jun 11, 2008, 07:42 UTC
Message-ID
<484F81FE.7070801@op5.se>
In-Reply-To
<alpine.LFD.1.10.0806101842460.3101@woody.linux-foundation.org>
Linus Torvalds wrote:
Show 33 quoted lines
> 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>
> ---
> 
> Junio, this is just the scaffolding, without the actual fsync_or_die call. 
> 
> I think it's a worthy place-holder regardless of whether we really want to 
> do the fsync (whether conditionally with a config option or not, and 
> whether there are more clever options like aio_fsync()).
> 
>  sha1_file.c |   17 +++++++++++------
>  1 files changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/sha1_file.c b/sha1_file.c
> index adcf37c..f311c79 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -2105,6 +2105,15 @@ int hash_sha1_file(const void *buf, unsigned long len, const char *type,
>  	return 0;
>  }
>  
> +/* Finalize a file on disk, and close it. */
> +static void close_sha1_file(int fd)

Why close_sha1_file() when it operates on any old file? I'd name it crash_safe_close() or perhaps close_and_fsync() or something instead, as it's got nothing to do with sha1's and everything to do with plain old files.

Other than that, I'm all for it.
-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Previous: Linus TorvaldsNext: Pierre Habouzit
Message 2 of 11 in “Consolidate SHA1 object file close”
  1. Linus TorvaldsJun 11, 2008
  2. Andreas EricssonJun 11, 2008
  3. Pierre HabouzitJun 11, 2008
  4. Linus TorvaldsJun 11, 2008
  5. Pierre HabouzitJun 11, 2008
  6. Linus TorvaldsJun 11, 2008
  7. Linus TorvaldsJun 11, 2008
  8. Pierre HabouzitJun 11, 2008
  9. Pierre HabouzitJun 11, 2008
  10. Linus TorvaldsJun 12, 2008
  11. Pierre HabouzitJun 12, 2008

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.