Skip to content

Commit 031d63d

Browse files
authored
Merge pull request #1034 from nexB/1007-resource-removal-error
Change ignore plugin logic #1007
2 parents e0c1245 + 58254c0 commit 031d63d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/scancode/plugin_ignore.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,23 @@ def process_codebase(self, codebase, ignore=(), **kwargs):
6464
}
6565

6666
ignorable = partial(is_ignored, ignores=ignores)
67-
67+
rids_to_remove = []
6868
remove_resource = codebase.remove_resource
69-
# first walk top down the codebase and collect ignored resource ids
69+
70+
# First, walk the codebase from the top-down and collect the rids of
71+
# Resources that can be removed.
7072
for resource in codebase.walk(topdown=True):
7173
if ignorable(resource.path):
7274
for child in resource.children(codebase):
73-
remove_resource(child)
75+
rids_to_remove.append(child.rid)
76+
rids_to_remove.append(resource.rid)
77+
78+
# Then, walk bottom-up and remove the ignored Resources from the
79+
# Codebase if the Resource's rid is in our list of rid's to remove.
80+
for resource in codebase.walk(topdown=False):
81+
resource_rid = resource.rid
82+
if resource_rid in rids_to_remove:
83+
rids_to_remove.remove(resource_rid)
7484
remove_resource(resource)
7585

7686

0 commit comments

Comments
 (0)