Re: [PATCH v2 16/21] read-cache: unlink old sharedindex files
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Dec 19, 2016, 11:58 UTC
- Message-ID
- <20161219115812.GD24125@ash>
- In-Reply-To
- <20161217145547.11748-17-chriscool@tuxfamily.org>
On Sat, Dec 17, 2016 at 03:55:42PM +0100, Christian Couder wrote:
Show 13 quoted lines
> +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_
Show 7 quoted lines
> + unlink(git_path("%s", de->d_name)))
> + error_errno(_("unable to unlink: %s"), git_path("%s", de->d_name));
> + }
> + closedir(dir);
> +
> + return 0;
> +}