Skip to content

Commit 50af77f

Browse files
committed
Create results_cache_index from filename instead of path
Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent 9c9acef commit 50af77f

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
@@ -1278,7 +1278,7 @@ def scan_codebase(
12781278
"""
12791279

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

12831283
use_threading = processes >= 0
12841284
runner = partial(
@@ -1415,7 +1415,7 @@ def terminate_pool_with_backoff(pool, number_of_trials=3):
14151415

14161416

14171417
def scan_resource(
1418-
location_path,
1418+
location_path_name,
14191419
scanners,
14201420
timeout=DEFAULT_TIMEOUT,
14211421
with_timing=False,
@@ -1443,7 +1443,7 @@ def scan_resource(
14431443
processing and threading works.
14441444
"""
14451445
scan_time = time()
1446-
location, path = location_path
1446+
location, path, name = location_path_name
14471447
results = {}
14481448
scan_errors = []
14491449
timings = {} if with_timing else None
@@ -1461,7 +1461,7 @@ def scan_resource(
14611461
results_cache_index = ''
14621462
if use_cached_results:
14631463
# compute results_cache_index
1464-
results_cache_index = results_cache.compute_results_cache_index(location=location, path=path)
1464+
results_cache_index = results_cache.compute_results_cache_index(location=location, filename=name)
14651465

14661466
# update `results` with cached data or add scanner to scanners_to_run if no
14671467
# 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)