Skip to content

Commit 764130e

Browse files
committed
Change ignore plugin logic #1007
* The ignore plugin first walks the codebase top-down to collect the rid's of the resources that are to be ignored * Then the plugin walks the codebase bottom up and removes resources if they are in the list of rids to remove Signed-off-by: Jono Yang <[email protected]>
1 parent a8c5544 commit 764130e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/scancode/plugin_ignore.py

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

6666
ignorable = partial(is_ignored, ignores=ignores)
67-
67+
rid_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)
74-
remove_resource(resource)
75+
rid_to_remove.append(child.rid)
76+
rid_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+
if ignorable(resource.path):
82+
if resource.rid in rid_to_remove:
83+
rid_to_remove.remove(resource.rid)
84+
remove_resource(resource)
7585

7686

7787
def is_ignored(location, ignores):

0 commit comments

Comments
 (0)