[bitbake-devel] [PATCH] utils: Use rm -rf in remove()
Peter Kjellerstedt
peter.kjellerstedt at axis.com
Fri Feb 8 13:47:47 UTC 2013
> -----Original Message-----
> From: bitbake-devel-bounces at lists.openembedded.org [mailto:bitbake-
> devel-bounces at 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 at 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
More information about the bitbake-devel
mailing list