Re: [PATCH 08/14] write_shared_index(): use tempfile module

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

 



Michael Haggerty <mhagger@xxxxxxxxxxxx> writes:

> Signed-off-by: Michael Haggerty <mhagger@xxxxxxxxxxxx>
> ---
>  read-cache.c | 37 +++++--------------------------------
>  1 file changed, 5 insertions(+), 32 deletions(-)

Nicely done.

>
> diff --git a/read-cache.c b/read-cache.c
> index 3e49c49..4f7b70f 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -2137,54 +2137,27 @@ static int write_split_index(struct index_state *istate,
>  	return ret;
>  }
>  
> -static char *temporary_sharedindex;
> -
> -static void remove_temporary_sharedindex(void)
> -{
> -	if (temporary_sharedindex) {
> -		unlink_or_warn(temporary_sharedindex);
> -		free(temporary_sharedindex);
> -		temporary_sharedindex = NULL;
> -	}
> -}
> -
> -static void remove_temporary_sharedindex_on_signal(int signo)
> -{
> -	remove_temporary_sharedindex();
> -	sigchain_pop(signo);
> -	raise(signo);
> -}
> +static struct tempfile temporary_sharedindex;
>  
>  static int write_shared_index(struct index_state *istate,
>  			      struct lock_file *lock, unsigned flags)
>  {
>  	struct split_index *si = istate->split_index;
> -	static int installed_handler;
>  	int fd, ret;
>  
> -	temporary_sharedindex = git_pathdup("sharedindex_XXXXXX");
> -	fd = mkstemp(temporary_sharedindex);
> +	fd = mks_tempfile(&temporary_sharedindex, git_path("sharedindex_XXXXXX"));
>  	if (fd < 0) {
> -		free(temporary_sharedindex);
> -		temporary_sharedindex = NULL;
>  		hashclr(si->base_sha1);
>  		return do_write_locked_index(istate, lock, flags);
>  	}
> -	if (!installed_handler) {
> -		atexit(remove_temporary_sharedindex);
> -		sigchain_push_common(remove_temporary_sharedindex_on_signal);
> -	}
>  	move_cache_to_base_index(istate);
>  	ret = do_write_index(si->base, fd, 1);
> -	close(fd);
>  	if (ret) {
> -		remove_temporary_sharedindex();
> +		delete_tempfile(&temporary_sharedindex);
>  		return ret;
>  	}
> -	ret = rename(temporary_sharedindex,
> -		     git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
> -	free(temporary_sharedindex);
> -	temporary_sharedindex = NULL;
> +	ret = rename_tempfile(&temporary_sharedindex,
> +			      git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
>  	if (!ret)
>  		hashcpy(si->base_sha1, si->base->sha1);
>  	return ret;
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[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]