summaryrefslogtreecommitdiff
path: root/pkg_resources.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2013-05-11 12:54:26 +0100
committerJason R. Coombs <jaraco@jaraco.com>2013-05-11 12:54:26 +0100
commit7adfcead12a21b2ed6b13f5a75477914b524cb12 (patch)
treed155fc6b1993106d1bc0494e77948ee7e3a2b052 /pkg_resources.py
parent9027ce5419a346e068927df72dbfcd650cdee33f (diff)
downloadpython-setuptools-git-7adfcead12a21b2ed6b13f5a75477914b524cb12.tar.gz
Extract method to determine if a temporary file is current.
--HG-- branch : distribute extra : rebase_source : ec2c1860f0ce9abbc3ea999aa54304ea9cc6ecd7
Diffstat (limited to 'pkg_resources.py')
-rw-r--r--pkg_resources.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/pkg_resources.py b/pkg_resources.py
index 579e3b46..b59f1703 100644
--- a/pkg_resources.py
+++ b/pkg_resources.py
@@ -1422,11 +1422,8 @@ class ZipProvider(EggProvider):
self.egg_name, self._parts(zip_path)
)
- if os.path.isfile(real_path):
- stat = os.stat(real_path)
- if stat.st_size==size and stat.st_mtime==timestamp:
- # size and stamp match, don't bother extracting
- return real_path
+ if self.is_current(real_path, zip_path):
+ return real_path
outf, tmpnam = _mkstemp(".$extract", dir=os.path.dirname(real_path))
os.write(outf, self.loader.get_data(zip_path))
@@ -1439,11 +1436,9 @@ class ZipProvider(EggProvider):
except os.error:
if os.path.isfile(real_path):
- stat = os.stat(real_path)
-
- if stat.st_size==size and stat.st_mtime==timestamp:
- # size and stamp match, somebody did it just ahead of
- # us, so we're done
+ if self._is_current(real_path, zip_path):
+ # the file became current since it was checked above,
+ # so proceed.
return real_path
elif os.name=='nt': # Windows, del old file and retry
unlink(real_path)
@@ -1456,6 +1451,16 @@ class ZipProvider(EggProvider):
return real_path
+ def _is_current(self, file_path, zip_path):
+ """
+ Return True if the file_path is current for this zip_path
+ """
+ timestamp, size = self._get_date_and_size(self.zipinfo[zip_path])
+ if not os.path.isfile(file_path):
+ return False
+ stat = os.stat(file_path)
+ return stat.st_size==size and stat.st_mtime==timestamp
+
def _get_eager_resources(self):
if self.eagers is None:
eagers = []