Subject: Re: [PATCH] builtin/clean.c: Handle disappearing files

From: Junio C Hamano <[email-masked]>
Date: Thu, 14 May 2015 14:45:27 -0700

David Turner <[email-masked]> writes:

> During a git clean, some other process might be deleting files as
> well.  If this happens, make git clean no longer die.
>
> Signed-off-by: David Turner <[email-masked]>
> ---

I am having a hard time to convince myself that this is a good
change.

For this change to be an improvement that matters, you must be
allowing some other process mucking around with the files in your
working tree when you run "git clean".  The original catches such
situation as an anomaly that the user would want to be aware of (and
investigate), but this patch essentially declares that having such a
random process touching your working tree from sideways is a normal
situation.  I do not think I am willing to make such a declaration
myself; I'd rather want to know why other people are touching my
working tree while I am working in it.

>  builtin/clean.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/clean.c b/builtin/clean.c
> index 98c103f..3ae44c2 100644
> --- a/builtin/clean.c
> +++ b/builtin/clean.c
> @@ -941,8 +941,16 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
>  		if (!cache_name_is_other(ent->name, ent->len))
>  			continue;
>  
> -		if (lstat(ent->name, &st))
> -			die_errno("Cannot lstat '%s'", ent->name);
> +		/*
> +		 * Some concurrent process might have already removed
> +		 * ent->name.
> +		 */
> +		if (lstat(ent->name, &st)) {
> +			if (errno == ENOENT || errno == ENOTDIR)
> +				continue;
> +			else
> +				die_errno("Cannot lstat '%s'", ent->name);
> +		}
>  
>  		if (pathspec.nr)
>  			matches = dir_path_match(ent, &pathspec, 0, NULL);