Re: [BUG] index corruption with git commit -p

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Sep 02, 2018 at 09:12:04AM +0200, Duy Nguyen wrote:

> > diff --git a/builtin/commit.c b/builtin/commit.c
> > index 0d9828e29e..779c5e2cb5 100644
> > --- a/builtin/commit.c
> > +++ b/builtin/commit.c
> > @@ -359,13 +359,6 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
> >  
> >  		discard_cache();
> >  		read_cache_from(get_lock_file_path(&index_lock));
> > -		if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
> > -			if (reopen_lock_file(&index_lock) < 0)
> > -				die(_("unable to write index file"));
> > -			if (write_locked_index(&the_index, &index_lock, 0))
> > -				die(_("unable to update temporary index"));
> > -		} else
> > -			warning(_("Failed to update main cache tree"));
> >
> 
> Narrowing down to this does help. This patch seems to fix it to me. I
> guess we have some leftover from the interactive add that should not
> be there after we have written the new index.
> 
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 2be7bdb331..60f30b3780 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -432,6 +432,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
>  		if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
>  			if (reopen_lock_file(&index_lock) < 0)
>  				die(_("unable to write index file"));
> +			ftruncate(index_lock.tempfile->fd, 0);
>  			if (write_locked_index(&the_index, &index_lock, 0))
>  				die(_("unable to update temporary index"));
>  		} else

Doh, of course. I even thought about this issue and dug all the way into
reopen_lock_file(), but for some reason temporarily forgot that O_WRONLY
does not imply O_TRUNC.

Arguably this should be the default for reopen_lockfile(), as getting a
write pointer into an existing file is not ever going to be useful for
the way Git uses lockfiles. Opening with O_APPEND could conceivably be
useful, but it's pretty unlikely (and certainly not helpful here, and
this is the only caller). Alternatively, the function should just take
open(2) flags.

At any rate, I think this perfectly explains the behavior we're seeing.

-Peff



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux