binman: Avoid changing a dict during iteration
authorSimon Glass <sjg@chromium.org>
Sat, 18 May 2019 04:00:45 +0000 (22:00 -0600)
committerSimon Glass <sjg@chromium.org>
Wed, 10 Jul 2019 22:52:58 +0000 (16:52 -0600)
This code works OK in Python 2 but Python 3 complains. Adjust it to avoid
deleting elements from a dict while iterating through it.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/binman/control.py

index ce25eb5485860614942dfb822a2aa1f12eef1860..20186ee1980282cfbd6b78d12d6ee1bbf7468fa3 100644 (file)
@@ -131,10 +131,13 @@ def Binman(options, args):
 
             if options.image:
                 skip = []
+                new_images = OrderedDict()
                 for name, image in images.items():
-                    if name not in options.image:
-                        del images[name]
+                    if name in options.image:
+                        new_images[name] = image
+                    else:
                         skip.append(name)
+                images = new_images
                 if skip and options.verbosity >= 2:
                     print('Skipping images: %s' % ', '.join(skip))