git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael J Gruber <git@drmicha.warpmail.net>
To: Alex Riesen <raa.lkml@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
	Junio C Hamano <gitster@pobox.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Subject: Re: [PATCH] Try to remove the given path even if it can't be opened
Date: Fri, 01 Apr 2011 15:37:44 +0200	[thread overview]
Message-ID: <4D95D528.6050409@drmicha.warpmail.net> (raw)
In-Reply-To: <AANLkTikfmXiZQquWi4STTCUy0qoY9J_waJ44nrPAvB1d@mail.gmail.com>

Alex Riesen venit, vidit, dixit 01.04.2011 10:29:
> Consider unreadable empty directories. rmdir(2) will remove
> them just fine, assuming the parent directory is modifiable.
> 
> Noticed by Linus.
> 
> Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
> ---
> On Fri, Apr 1, 2011 at 00:01, Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
>> Which is kind of understandable, but at the same time, if it's empty,
>> a "rmdir()" will just work. So git gave up a bit too soon.
> ...
>> Now, I realize that if the directory isn't empty, and is unreadable,
>> we really should give up (although a better error message about _why_
>> we failed may be in order) rather than try to chmod it or anything
>> like that. But the simple "try to rmdir it" might be a good addition
>> for the trivial case.
> 
> It is not tested, but looks trivial. The system I made it on is a Cygwin

Famous last words...

> machine, and a test from last master pull is still running (since two days).
> And sorry, it is not based on master. Should apply without problems, though.
> 
> ---
>  dir.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/dir.c b/dir.c
> index 325fb56..7251426 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -1191,8 +1191,11 @@ int remove_dir_recursively(struct strbuf *path, int flag)
>  		return 0;
> 
>  	dir = opendir(path->buf);
> -	if (!dir)
> +	if (!dir) {
> +		if (rmdir(path->buf) == 0)
> +			return 0;
>  		return -1;
> +	}
>  	if (path->buf[original_len - 1] != '/')
>  		strbuf_addch(path, '/');
> 

How about simply

if (!dir)
	return rmdir(path->buf);

like we do later on in that function?

Michael

  reply	other threads:[~2011-04-01 13:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-01  8:29 [PATCH] Try to remove the given path even if it can't be opened Alex Riesen
2011-04-01 13:37 ` Michael J Gruber [this message]
2011-04-01 14:01   ` Alex Riesen
2011-04-01 18:08 ` Junio C Hamano
2011-04-02 20:09   ` Alex Riesen
2011-04-02 20:33     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D95D528.6050409@drmicha.warpmail.net \
    --to=git@drmicha.warpmail.net \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=raa.lkml@gmail.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).