Skip to content

Commit 60ef115

Browse files
committed
Sort combined scan headers #1439
* Update comments Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent c0c6bd6 commit 60ef115

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/scancode/cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,11 @@ def echo_func(*_args, **_kwargs):
544544
elif len(input) == 1:
545545
# we received a single input path, so we treat this as a single path
546546
input = input[0] # NOQA
547+
548+
# This is the case where we have a list of inputs, but the list of inputs are not from the
549+
# `from_json` option. If the `from_json` option is available and we have a list of inputs
550+
# from it, we can pass `input` just fine when we create a VirtualCodebase, otherwise we have to
551+
# process `input` below.
547552
elif not from_json:
548553
# we received a several input paths: we can handle this IFF they share
549554
# a common root directory and none is an absolute path

src/scancode/resource.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ def _get_scan_data(self, location):
14011401
- a JSON string
14021402
- a Python mapping
14031403
1404-
or `location` is a List that contains multiple paths to scans that are to be joined together.
1404+
or `location` is a List or a Tuple that contains multiple paths to scans that are to be joined together.
14051405
"""
14061406
if isinstance(location, dict):
14071407
return location
@@ -1411,6 +1411,7 @@ def _get_scan_data(self, location):
14111411
scan_data = self._get_scan_data_helper(loc)
14121412
combined_scan_data['headers'].extend(scan_data['headers'])
14131413
combined_scan_data['files'].extend(scan_data['files'])
1414+
combined_scan_data['headers'] = sorted(combined_scan_data['headers'], key=lambda x: x['start_timestamp'])
14141415
return combined_scan_data
14151416
return self._get_scan_data_helper(location)
14161417

@@ -1544,6 +1545,7 @@ def _populate(self, scan_data):
15441545
# Create root resource without setting root data just yet. If we run into the root data
15451546
# while we iterate through `resources_data`, we fill in the data then.
15461547

1548+
# Create a virtual root if we are merging multiple scans together
15471549
multiple_input = isinstance(self.location, (list, tuple,)) and len(self.location) > 1
15481550
if multiple_input:
15491551
root_path = 'virtual_root'
@@ -1562,6 +1564,7 @@ def _populate(self, scan_data):
15621564

15631565
for resource_data in resources_data:
15641566
path = resource_data.get('path')
1567+
# Append virtual_root path to imported Resource path if we are merging multiple scans
15651568
if multiple_input:
15661569
path = os.path.join(root_path, path)
15671570
name = resource_data.get('name', None)

0 commit comments

Comments
 (0)