Patchwork [bitbake-devel,2/2] fetch2: fix traceback when a wildcard matches a directory

login
register
mail settings
Submitter Paul Eggleton
Date April 8, 2014, 2:03 p.m.
Message ID <0dabe179e605bc4d777431c7740dd4a53d9572fa.1396965331.git.paul.eggleton@linux.intel.com>
Download mbox | patch
Permalink /patch/70293/
State New
Headers show

Comments

Paul Eggleton - April 8, 2014, 2:03 p.m.
If there is a directory matching a wildcard in SRC_URI when getting file
checksums, we should recurse into that instead of producing an error.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 lib/bb/fetch2/__init__.py | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

Patch

diff --git a/lib/bb/fetch2/__init__.py b/lib/bb/fetch2/__init__.py
index a9ab75e..5a03a0e 100644
--- a/lib/bb/fetch2/__init__.py
+++ b/lib/bb/fetch2/__init__.py
@@ -962,24 +962,32 @@  def get_file_checksums(filelist, pn):
             return None
         return checksum
 
+    def checksum_dir(pth):
+        # Handle directories recursively
+        dirchecksums = []
+        for root, dirs, files in os.walk(pth):
+            for name in files:
+                fullpth = os.path.join(root, name)
+                checksum = checksum_file(fullpth)
+                if checksum:
+                    dirchecksums.append((fullpth, checksum))
+        return dirchecksums
+
     checksums = []
     for pth in filelist.split():
         checksum = None
         if '*' in pth:
             # Handle globs
             for f in glob.glob(pth):
-                checksum = checksum_file(f)
-                if checksum:
-                    checksums.append((f, checksum))
+                if os.path.isdir(f):
+                    checksums.extend(checksum_dir(f))
+                else:
+                    checksum = checksum_file(f)
+                    if checksum:
+                        checksums.append((f, checksum))
             continue
         elif os.path.isdir(pth):
-            # Handle directories
-            for root, dirs, files in os.walk(pth):
-                for name in files:
-                    fullpth = os.path.join(root, name)
-                    checksum = checksum_file(fullpth)
-                    if checksum:
-                        checksums.append((fullpth, checksum))
+            checksums.extend(checksum_dir(pth))
             continue
         else:
             checksum = checksum_file(pth)