From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: Daniel Barkalow <barkalow@iabervon.org>, git@vger.kernel.org
Subject: Re: [PATCH 1/2] Introduce remove_dir_recursively()
Date: Fri, 28 Sep 2007 13:35:21 +0100 (BST) [thread overview]
Message-ID: <Pine.LNX.4.64.0709281323300.28395@racer.site> (raw)
In-Reply-To: <7v8x6rqhwy.fsf@gitster.siamese.dyndns.org>
Hi,
On Fri, 28 Sep 2007, Junio C Hamano wrote:
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
> > +int remove_dir_recursively(char *path, int len, int only_empty)
> > +{
> > ...
> > + namlen = strlen(e->d_name);
> > + if (len + namlen > PATH_MAX ||
> > + !memcpy(path + len, e->d_name, namlen) ||
> > + (path[len + namlen] = '\0') ||
> > + lstat(path, &st))
> > + ; /* fall thru */
> > + else if (S_ISDIR(st.st_mode)) {
> > + if (!remove_dir_recursively(path, len + namlen,
> > + only_empty))
> > + continue; /* happy */
> > + } else if (!only_empty &&
> > + len + namlen + 1 < PATH_MAX &&
> > + !unlink(path))
> > + continue; /* happy, too */
> > +
> > + /* path too long, stat fails, or non-directory still exists */
> > + ret = -1;
> > + break;
>
> Is it only me who finds the first if () condition way too
> convoluted and needs to read three times to convince oneself
> that it is doing a sane thing?
>
> Please, especially...
>
> * For $DEITY's sake, memcpy() returns pointer to dst which you
> know is not NULL. so !memcpy() is always false here, which
> might be _convenient_ for you and the compiler but not for
> a human reader of the code who needs to blink twice wondering
> if you meant !memcmp().
>
> * Same for (path[] = '\0'), wondering if it is misspelled
> (path[] == '\0').
Okay, will fix (with an evil goto).
BTW it just hit me that this magic reliance on a buffer of size PATH_MAX
is not good at all. It even hit _me_ while developing that series.
So I'll change that to a strbuf, too. (Which will fix the convoluted
logic quite some, incidentally.)
Ciao,
Dscho
next prev parent reply other threads:[~2007-09-28 12:36 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-28 5:06 [PATCH 0/2] rsync support Johannes Schindelin
2007-09-28 5:06 ` [PATCH 1/2] Introduce remove_dir_recursively() Johannes Schindelin
2007-09-28 9:05 ` Junio C Hamano
2007-09-28 12:35 ` Johannes Schindelin [this message]
2007-09-28 22:14 ` David Kastrup
2007-09-28 5:07 ` [PATCH 2/2] fetch/push: readd rsync support Johannes Schindelin
2007-09-28 5:20 ` Shawn O. Pearce
2007-09-28 12:22 ` Johannes Schindelin
2007-09-28 9:30 ` Junio C Hamano
2007-09-28 12:53 ` Johannes Schindelin
2007-09-28 15:28 ` [PATCH v2 0/2] rsync support, was Re: [PATCH 0/2] " Johannes Schindelin
2007-09-28 15:28 ` [PATCH v2 1/2] Introduce remove_dir_recursively() Johannes Schindelin
2007-09-28 15:29 ` [PATCH 2/2] fetch/push: readd rsync support Johannes Schindelin
2007-09-28 15:30 ` Johannes Schindelin
2007-09-28 21:20 ` Junio C Hamano
2007-09-28 22:48 ` Johannes Schindelin
2007-09-29 0:35 ` [PATCH v3 " Johannes Schindelin
2007-09-30 6:09 ` Junio C Hamano
2007-09-30 12:58 ` Johannes Schindelin
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=Pine.LNX.4.64.0709281323300.28395@racer.site \
--to=johannes.schindelin@gmx.de \
--cc=barkalow@iabervon.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).