bitbake: utils: Use rm -rf in remove()
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Sun, 3 Feb 2013 16:51:34 +0000 (16:51 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 15 Feb 2013 15:53:41 +0000 (15:53 +0000)
Whilst shutils.rmtree() is pythonic, its also slow. Its faster to
use rm -rf which makes optimial use of the right syscalls.

(Bitbake rev: 96088ebdec08e49ba9e8dbcac437bfcdc21f5983)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
bitbake/lib/bb/utils.py

index b1a0f25..8c363df 100644 (file)
@@ -535,14 +535,17 @@ def remove(path, recurse=False):
     """Equivalent to rm -f or rm -rf"""
     if not path:
         return
-    import os, errno, shutil, glob
+    if recurse:
+        import subprocess
+        # shutil.rmtree(name) would be ideal but its too slow
+        subprocess.call("rm -rf %s" % path, shell=True)
+        return
+    import os, errno, glob
     for name in glob.glob(path):
         try:
             os.unlink(name)
         except OSError as exc:
-            if recurse and exc.errno == errno.EISDIR:
-                shutil.rmtree(name)
-            elif exc.errno != errno.ENOENT:
+            if exc.errno != errno.ENOENT:
                 raise
 
 def prunedir(topdir):