git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: otalpster <otalpster@gmail.com>
To: Matheus Tavares Bernardino <matheus.bernardino@usp.br>
Cc: Junio C Hamano <gitster@pobox.com>, git <git@vger.kernel.org>,
	Michael Haggerty <mhagger@alum.mit.edu>
Subject: Re: [PATCH] entry.c: use dir-iterator to avoid explicit dir traversal
Date: Mon, 16 Dec 2019 18:12:12 +0200	[thread overview]
Message-ID: <CAEKpa1QqrxyS1jeAUoSEAM2bC5h+trPJc_Mm1M18NVA73sCWKQ@mail.gmail.com> (raw)
In-Reply-To: <CAHd-oW5tVNP=yNZqPANkk4JLWKJyPkb4g4AeUerrd1O=xdLKXQ@mail.gmail.com>

On Tue, Dec 10, 2019 at 6:38 AM Matheus Tavares Bernardino
<matheus.bernardino@usp.br> wrote:
>
> On Mon, Dec 9, 2019 at 6:18 PM Junio C Hamano <gitster@pobox.com> wrote:
> >
> > Matheus Tavares Bernardino <matheus.bernardino@usp.br> writes:
> >
> > >> The changes pass the test suite t/ and Travis CI.
> > >> Please point out any mistakes.
> > >> ...
> > >> -               strbuf_addch(path, '/');
> > >> -               strbuf_addstr(path, de->d_name);
> > >> -               if (lstat(path->buf, &st))
> > >> -                       die_errno("cannot lstat '%s'", path->buf);
> > >> -               if (S_ISDIR(st.st_mode))
> > >> -                       remove_subtree(path);
> > >> -               else if (unlink(path->buf))
> > >> -                       die_errno("cannot unlink '%s'", path->buf);
> > >> -               strbuf_setlen(path, origlen);
> > >> +               if (unlink(iter->path.buf)) {
> > >
> > > unlink()-ing a directory in Linux will return a EISDIR error. So I
> > > think you still need to use S_ISDIR() to check if iter->path.buf is a
> > > directory and call rmdir(), in this case.
> > >
> > > However, note that the dir-iterator API gives entries in pre-order.
> > > I.e. a directory appears before its subentries. In the use case of
> > > remove_subtree(), though, we need to traverse in post-order, since we
> > > have to remove the subentries before removing the directory where they
> > > reside. My suggestion is that you add a preliminary patch,
> > > implementing a new DIR_ITERATOR_POST_ORDER flag to dir-iterator.h, and
> > > then use it in this patch.
> >
> > Thanks for a review and a few hints to nudge a new contributor in
> > the right direction.  Very much appreciated.
> >
> > I wonder why the bugs in this patch weren't caught by self test we
> > already have, by the way.  We need a bit better test coverage,
> > perhaps?
>
> I think there is no current test that covers remove_subtree() being
> called with nested directories. But we could use the test proposed by
> Daniel[1], which does fail when this current patch is applied. So,
> maybe, Plato could also include this test in v2, before performing the
> dir-iterator convertion.
>
> [1]: https://public-inbox.org/git/1493226219-33423-3-git-send-email-bnmvco@gmail.com/

Hello!
Thanks for the warm welcome and sorry for the late reply.
Your review and hints you provided were very helpful and appreciated.

Yes, I can work and include the test in v2, as well as performing the
dir-iterator conversion. The required process and the necessary
changes I need to make were very clear.

This week I'm very busy. I'll work on this in great detail from next week.

Thanks,
Plato

      reply	other threads:[~2019-12-16 16:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-08 18:04 [PATCH] entry.c: use dir-iterator to avoid explicit dir traversal otalpster
2019-12-09 15:21 ` Derrick Stolee
2019-12-09 17:41 ` Matheus Tavares Bernardino
2019-12-09 21:18   ` Junio C Hamano
2019-12-10  4:38     ` Matheus Tavares Bernardino
2019-12-16 16:12       ` otalpster [this message]

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=CAEKpa1QqrxyS1jeAUoSEAM2bC5h+trPJc_Mm1M18NVA73sCWKQ@mail.gmail.com \
    --to=otalpster@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=matheus.bernardino@usp.br \
    --cc=mhagger@alum.mit.edu \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).