From cb4b1a9e751b10d63d91197934d1d8f8fff44be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Tue, 15 Apr 2014 23:27:23 +0200 Subject: clean up easy_install.uncache_zipdir() code & comments --HG-- extra : rebase_source : 79778a670897cb92c17307f2535fcac6447e16b4 --- setuptools/command/easy_install.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 10176874..8c281590 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1583,18 +1583,30 @@ def auto_chmod(func, arg, exc): reraise(et, (ev[0], ev[1] + (" %s %s" % (func,arg)))) def uncache_zipdir(path): - """Ensure that the importer caches dont have stale info for `path`""" - from zipimport import _zip_directory_cache as zdc - _uncache(path, zdc) + """ + Remove any globally cached zip file related data for `path` + + Stale zipimport.zipimporter objects need to be removed when a zip file is + replaced as they contain cached zip file directory information. If they are + asked to get data from their zip file, they will use that cached + information to calculate the data location in the zip file. This calculated + location may be incorrect for the replaced zip file, which may in turn + cause the read operation to either fail or return incorrect data. + + Note we have no way to clear any local caches from here. That is left up to + whomever is in charge of maintaining that cache. + + """ + _uncache(path, zipimport._zip_directory_cache) _uncache(path, sys.path_importer_cache) def _uncache(path, cache): if path in cache: del cache[path] else: - path = normalize_path(path) + normalized_path = normalize_path(path) for p in cache: - if normalize_path(p)==path: + if normalize_path(p) == normalized_path: del cache[p] return -- cgit v1.2.1