Subject: Re: [PATCH v2 16/21] read-cache: unlink old sharedindex files

From: Duy Nguyen <[email-masked]>
Date: Mon, 19 Dec 2016 18:58:13 +0700

On Sat, Dec 17, 2016 at 03:55:42PM +0100, Christian Couder wrote:
> +static int clean_shared_index_files(const char *current_hex)
> +{
> +	struct dirent *de;
> +	DIR *dir = opendir(get_git_dir());
> +
> +	if (!dir)
> +		return error_errno(_("unable to open git dir: %s"), get_git_dir());
> +
> +	while ((de = readdir(dir)) != NULL) {
> +		const char *sha1_hex;
> +		if (!skip_prefix(de->d_name, "sharedindex.", &sha1_hex))
> +			continue;
> +		if (!strcmp(sha1_hex, current_hex))

fspathcmp since we're dealing fs paths?

In theory we should be ok using strcmp, even on Windows because case
is preserved, I think. It's only a problem when we write path 'abc'
down and read 'ABC' back.

Oh well.. your call because if you go with fspathcmp, skip_prefix can't
be used either. A lot more changes for a very rare case.

> +			continue;
> +		if (can_delete_shared_index(sha1_hex) > 0 &&

Probably shorter to pass full d->name here so you don't have to do
another git_path() in can_delete_

> +		    unlink(git_path("%s", de->d_name)))
> +			error_errno(_("unable to unlink: %s"), git_path("%s", de->d_name));
> +	}
> +	closedir(dir);
> +
> +	return 0;
> +}