From patchwork Thu Feb 7 23:55:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [bitbake-devel] utils: Use rm -rf in remove() Date: Thu, 07 Feb 2013 23:55:02 -0000 From: Richard Purdie X-Patchwork-Id: 44303 Message-Id: <1360281302.10722.68.camel@ted> To: bitbake-devel 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 --- 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 + subprocess.call('rm -rf %s' % path, shell=True) + return elif exc.errno != errno.ENOENT: raise