Skip to content

Commit 34708ec

Browse files
Fix strip_root not removing root directory from Resource paths
Signed-off-by: Kaushik <kaushikrjpm10@gmail.com>
1 parent 92b4396 commit 34708ec

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/scancode/cli.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,16 @@ def echo_func(*_args, **_kwargs):
10701070
results = get_results(codebase, as_list=True, **requested_options)
10711071
elif return_codebase:
10721072
results = codebase
1073+
# Strip root from paths when strip_root is enabled.
1074+
# See https://github.com/aboutcode-org/scancode-toolkit/issues/2985
1075+
if strip_root and not codebase.has_single_resource:
1076+
from commoncode.resource import strip_first_path_segment
1077+
new_resources_by_path = {}
1078+
for old_path, resource in list(codebase.resources_by_path.items()):
1079+
stripped_path = strip_first_path_segment(old_path)
1080+
resource.path = stripped_path
1081+
new_resources_by_path[stripped_path] = resource
1082+
codebase.resources_by_path = new_resources_by_path
10731083

10741084
finally:
10751085
# remove temporary files

0 commit comments

Comments
 (0)