Re: [PATCH v4 17/22] read-cache: unlink old sharedindex files

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

 



Christian Couder <christian.couder@xxxxxxxxx> writes:

> +static int can_delete_shared_index(const char *shared_index_path)
> +{
> +	struct stat st;
> +	unsigned long expiration;
> +
> +	/* Check timestamp */
> +	expiration = get_shared_index_expire_date();
> +	if (!expiration)
> +		return 0;
> +	if (stat(shared_index_path, &st))
> +		return error_errno(_("could not stat '%s"), shared_index_path);
> +	if (st.st_mtime > expiration)
> +		return 0;
> +
> +	return 1;
> +}
> +
> +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;
> +		const char *shared_index_path;
> +		if (!skip_prefix(de->d_name, "sharedindex.", &sha1_hex))
> +			continue;
> +		if (!strcmp(sha1_hex, current_hex))
> +			continue;
> +		shared_index_path = git_path("%s", de->d_name);
> +		if (can_delete_shared_index(shared_index_path) > 0 &&

Is this "can" or "should"?  This sounds like the latter.

> +		    unlink(shared_index_path))
> +			error_errno(_("unable to unlink: %s"), shared_index_path);

This does not make the entire operation to fail (and I think the
behaviour you have here is preferrable--we just want to report
without failing the main operation).

But should it be reported as "error: unable to unlink"?  It may be
better to give this message as a warning.



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