Subject: Re: [PATCH v6 4/7] pack-bitmap.c: don't ignore ENOENT silently

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Mon, 11 Jul 2022 16:38:01 +0200

On Mon, Jul 11 2022, Teng Long wrote:

> When finished call git_open(), instead of ignoring ENOENT silently
> and return error_errno(_("cannot stat...")), it's better to check
> the ENOENT before then output the warning.

Makes sense, but...

> -	if (fd < 0)
> +	if (fd < 0) {
> +		if (errno != ENOENT)
> +			warning("'%s' cannot open '%s'", strerror(errno), bitmap_name);

This should just be warning_errno("cannot open '%s'", bitmap_name),
unless I'm missing something...

> +		free(bitmap_name);
>  		return -1;
> +	}
> +	free(bitmap_name);
>  
>  	if (fstat(fd, &st)) {
>  		close(fd);
> @@ -376,10 +379,14 @@ static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git
>  
>  	bitmap_name = pack_bitmap_filename(packfile);
>  	fd = git_open(bitmap_name);
> -	free(bitmap_name);
>  
> -	if (fd < 0)
> +	if (fd < 0) {
> +		if (errno != ENOENT)
> +			warning("'%s' cannot open '%s'", strerror(errno), bitmap_name);

...ditto.

> +		free(bitmap_name);
>  		return -1;
> +	}
> +	free(bitmap_name);
>  	if (fstat(fd, &st)) {
>  		close(fd);