All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
To: Richard Purdie <richard.purdie@linuxfoundation.org>,
	bitbake-devel <bitbake-devel@lists.openembedded.org>
Subject: Re: [PATCH] utils: Use rm -rf in remove()
Date: Fri, 8 Feb 2013 14:47:47 +0100	[thread overview]
Message-ID: <A612847CFE53224C91B23E3A5B48BAC755FD6C1E82@xmail3.se.axis.com> (raw)
In-Reply-To: <1360281302.10722.68.camel@ted>

> -----Original Message-----
> From: bitbake-devel-bounces@lists.openembedded.org [mailto:bitbake-
> devel-bounces@lists.openembedded.org] On Behalf Of Richard Purdie
> Sent: den 8 februari 2013 00:55
> To: bitbake-devel
> Subject: [bitbake-devel] [PATCH] utils: Use rm -rf in remove()
> 
> Whilst shutils.rmtree() is pythonic, its also slow. Its faster to
> use rm -rf which makes optimal use of the right syscalls.
> 
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> ---
> diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
> index 484fb2d..94ef447 100644
> --- a/bitbake/lib/bb/utils.py
> +++ b/bitbake/lib/bb/utils.py
> @@ -533,13 +533,15 @@ def remove(path, recurse=False):
>      """Equivalent to rm -f or rm -rf"""
>      if not path:
>          return
> -    import os, errno, shutil, glob
> +    import os, errno, glob, subprocess
>      for name in glob.glob(path):
>          try:
>              os.unlink(name)
>          except OSError as exc:
>              if recurse and exc.errno == errno.EISDIR:
> -                shutil.rmtree(name)
> +                # shutil.rmtree(name) would be ideal but its too slow

its -> it is

> +                subprocess.call('rm -rf %s' % path, shell=True)
> +                return

Shouldn't the last two lines above be:

                   subprocess.call('rm -rf %s' % name, shell=True)

to maintain behavior.

>              elif exc.errno != errno.ENOENT:
>                  raise

Alternatively, wouldn't it be better to check for recurse 
first:

    if recurse:
        import subprocess
        subprocess.call('rm -rf %s' % path, shell=True)
    else:
        import os, errno, glob
        for name in glob.glob(path):
            try:
                os.unlink(name)
            except OSError as exc:
                if exc.errno != errno.ENOENT:
                    raise

//Peter





      parent reply	other threads:[~2013-02-08 14:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-07 23:55 [PATCH] utils: Use rm -rf in remove() Richard Purdie
2013-02-08  1:08 ` Chris Larson
2013-02-15 16:00   ` Richard Purdie
2013-02-16 13:51     ` Martin Ertsås
2013-02-16 14:54       ` Richard Purdie
2013-02-16 15:27         ` Martin Ertsås
2013-02-08 13:47 ` Peter Kjellerstedt [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

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

  git send-email \
    --in-reply-to=A612847CFE53224C91B23E3A5B48BAC755FD6C1E82@xmail3.se.axis.com \
    --to=peter.kjellerstedt@axis.com \
    --cc=bitbake-devel@lists.openembedded.org \
    --cc=richard.purdie@linuxfoundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.