Commit 3e6ecb09 authored by Jurko Gospodnetić's avatar Jurko Gospodnetić

clear cached zip archive directory data when removing it from cache

This is an extra safety measure to avoid someone holding a reference to this
cached data and using its content even after we know that the underlying zip
archive has been removed and possibly even replaced.

Change suggested by PJ Eby (pje on BitBucket) in a setuptools pull request #51
comment:
  https://bitbucket.org/pypa/setuptools/pull-request/51/diff#comment-2018183

--HG--
extra : rebase_source : 6de2309bc7446647749cfe78ab00e0230a07f92f
parent 9101bdd5
......@@ -1646,16 +1646,21 @@ def update_dist_caches(dist_path, fix_zipimporter_caches):
if fix_zipimporter_caches:
_replace_zip_directory_cache_data(normalized_path)
else:
# Clear the relevant zipimport._zip_directory_cache data. This will not
# remove related zipimport.zipimporter instances but should at least
# not leave the old zip archive directory data behind to be reused by
# some newly created zipimport.zipimporter loaders. This whole stale
# data removal step does not seem strictly necessary, but has been left
# in because it was done before we started replacing the zip archive
# directory information cache content if possible, and there are no
# relevant unit tests that we can depend on to tell us if this is
# really needed.
_uncache(normalized_path, zipimport._zip_directory_cache)
# Here, even though we do not want to fix existing and now stale
# zipimporter cache information, we still want to remove it. Related to
# Python's zip archive directory information cache, we clear each of
# its stale entries in two phases:
# 1. Clear the entry so attempting to access zip archive information
# via any existing stale zipimport.zipimporter instances fails.
# 2. Remove the entry from the cache so any newly constructed
# zipimport.zipimporter instances do not end up using old stale
# zip archive directory information.
# This whole stale data removal step does not seem strictly necessary,
# but has been left in because it was done before we started replacing
# the zip archive directory information cache content if possible, and
# there are no relevant unit tests that we can depend on to tell us if
# this is really needed.
_remove_and_clear_zip_directory_cache_data(normalized_path)
def _collect_zipimporter_cache_entries(normalized_path, cache):
"""
......@@ -1723,6 +1728,13 @@ def _replace_zip_directory_cache_data(normalized_path):
zipimport._zip_directory_cache,
updater=replace_cached_zip_archive_directory_data)
def _remove_and_clear_zip_directory_cache_data(normalized_path):
def clear_and_remove_cached_zip_archive_directory_data(path, old_entry):
old_entry.clear()
_update_zipimporter_cache(normalized_path,
zipimport._zip_directory_cache,
updater=clear_and_remove_cached_zip_archive_directory_data)
def is_python(text, filename='<string>'):
"Is this string a valid Python script?"
try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment