Skip to content

Commit 956183e

Browse files
Fix parent() method for strip_root to handle empty parent paths
Signed-off-by: Kaushik <kaushikrjpm10@gmail.com>
1 parent 34708ec commit 956183e

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/scancode/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,17 @@ def echo_func(*_args, **_kwargs):
10801080
resource.path = stripped_path
10811081
new_resources_by_path[stripped_path] = resource
10821082
codebase.resources_by_path = new_resources_by_path
1083+
1084+
# Fix parent() to handle empty parent_path for direct children of root.
1085+
# commoncode's parent() uses `return path and get_resource(path)` which
1086+
# returns '' (empty string) when path is '', breaking tree traversal.
1087+
original_parent = codebase.resource_class.parent
1088+
def patched_parent(self, codebase_arg):
1089+
parent_path = self.parent_path()
1090+
if parent_path == '':
1091+
return codebase_arg.root
1092+
return original_parent(self, codebase_arg)
1093+
codebase.resource_class.parent = patched_parent
10831094

10841095
finally:
10851096
# remove temporary files

0 commit comments

Comments
 (0)