Skip to content

Commit

Permalink
still trying to fix cache
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJi22 committed Jun 17, 2022
1 parent 4417614 commit 60d0c6a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/licensedcode/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def load_or_build(
# bypass build if cache exists
if has_cache and not force:
try:
# save the list of additional directories included in the cache, or None if the cache does not
# include any additional directories
with open(cached_directories_file, 'wb') as file:
pickle.dump(additional_directories, file, protocol=PICKLE_PROTOCOL)
return load_cache_file(cache_file)
except Exception as e:
# work around some rare Windows quirks
Expand Down Expand Up @@ -387,12 +391,13 @@ def need_cache_rebuild(additional_directories):
# if we have cached additional directories of licenses, check if those licenses are equal to the additional
# directories passed in
with open(cached_directories_file, 'rb') as file:
cached_additional_directories = pickle.load(file)
# it's possible that pickle.load(file) results in None
cached_additional_directories = pickle.load(file) or set()

# we need to rebuild the cache if the list of additional directories we passed in is not a subset of
# the set of additional directories currently included in the index cache
should_rebuild_cache = additional_directories is not None and cached_additional_directories is not None\
and not set(additional_directories).issubset(set(cached_additional_directories))
should_rebuild_cache = additional_directories is not None \
and not set(additional_directories).issubset(cached_additional_directories)
else:
# otherwise, we don't have a file of cached directories. If there are additional directories passed in,
# we know we need to make a new cache file.
Expand Down

0 comments on commit 60d0c6a

Please sign in to comment.