Skip to content

Commit 68ec4be

Browse files
committed
Create results_cache_index from filename instead of path
Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent 51cf6d7 commit 68ec4be

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

src/scancode/cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ def scan_codebase(
13411341
"""
13421342

13431343
# NOTE: we never scan directories
1344-
resources = ((r.location, r.path) for r in codebase.walk() if r.is_file)
1344+
resources = ((r.location, r.path, r.name) for r in codebase.walk() if r.is_file)
13451345

13461346
use_threading = processes >= 0
13471347
runner = partial(
@@ -1478,7 +1478,7 @@ def terminate_pool_with_backoff(pool, number_of_trials=3):
14781478

14791479

14801480
def scan_resource(
1481-
location_path,
1481+
location_path_name,
14821482
scanners,
14831483
timeout=DEFAULT_TIMEOUT,
14841484
with_timing=False,
@@ -1506,7 +1506,7 @@ def scan_resource(
15061506
processing and threading works.
15071507
"""
15081508
scan_time = time()
1509-
location, path = location_path
1509+
location, path, name = location_path_name
15101510
results = {}
15111511
scan_errors = []
15121512
timings = {} if with_timing else None
@@ -1524,7 +1524,7 @@ def scan_resource(
15241524
results_cache_index = ''
15251525
if use_cached_results:
15261526
# compute results_cache_index
1527-
results_cache_index = results_cache.compute_results_cache_index(location=location, path=path)
1527+
results_cache_index = results_cache.compute_results_cache_index(location=location, filename=name)
15281528

15291529
# update `results` with cached data or add scanner to scanners_to_run if no
15301530
# cache data is available

src/scancode/results_cache.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ def hasher_from_chunks(chunks):
2626
return hasher
2727

2828

29-
def compute_results_cache_index(location, path):
29+
def compute_results_cache_index(location, filename):
3030
"""
3131
Compute results_cache_index value for a Resource at `location`.
3232
"""
3333
chunks = binary_chunks(location=location)
3434
sha256_hasher = hasher_from_chunks(chunks=chunks)
35-
# TODO: consider using filename instead of path
36-
sha256_hasher.update(path.encode('utf-8', 'surrogateescape'))
35+
sha256_hasher.update(filename.encode('utf-8', 'surrogateescape'))
3736
return sha256_hasher.hexdigest()
3837

3938

0 commit comments

Comments
 (0)