Skip to content

Commit

Permalink
Only get mtime on local links. Fixes #29
Browse files Browse the repository at this point in the history
Under certain circumstances it is possible for a remote link to have
os.path.getmtime called on it during resolve when using caching.  Instead,
consider all remote links as cache hits, and only filter local links using
mtime.
  • Loading branch information
wickman committed Dec 3, 2014
1 parent 443d337 commit 224b6b0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
CHANGES
=======

-----
0.8.1
-----

* Bug fix: Fix issue where it'd be possible to ``os.path.getmtime`` on a remote ``Link`` object
`Issue #29 <https://github.com/pantsbuild/pex/issues/29>`_

-----
0.8.0
-----
Expand Down
9 changes: 6 additions & 3 deletions pex/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def packages_from_requirement_cached(local_iterator, ttl, iterator, requirement,
# match with inexact requirement, consider if ttl supplied.
if ttl:
now = time.time()
packages = [package for package in packages if (now - os.path.getmtime(package.path)) < ttl]
packages = [package for package in packages if package.remote or package.local and
(now - os.path.getmtime(package.path)) < ttl]
if packages:
TRACER.log('Package cache hit (inexact): %s' % requirement, V=3)
return packages
Expand Down Expand Up @@ -187,13 +188,15 @@ def resolve(

def requires(package, requirement):
if not distributions.has(package):
local_package = Package.from_href(context.fetch(package, into=cache))
with TRACER.timed('Fetching %s' % package.url, V=2):
local_package = Package.from_href(context.fetch(package, into=cache))
if package.remote:
# this was a remote resolution -- so if we copy from remote to local but the
# local already existed, update the mtime of the local so that it is correct
# with respect to cache_ttl.
os.utime(local_package.path, None)
dist = translator.translate(local_package, into=cache)
with TRACER.timed('Translating %s into distribution' % local_package.path, V=2):
dist = translator.translate(local_package, into=cache)
if dist is None:
raise Untranslateable('Package %s is not translateable.' % package)
if not distribution_compatible(dist, interpreter, platform):
Expand Down
2 changes: 1 addition & 1 deletion pex/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.8.0'
__version__ = '0.8.1'
4 changes: 4 additions & 0 deletions tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ def test_simple_local_resolve():
fetchers = [Fetcher([td])]
dists = resolve(['project'], fetchers=fetchers)
assert len(dists) == 1


# TODO(wickman) Test resolve and cached resolve more directly than via
# integration.

0 comments on commit 224b6b0

Please sign in to comment.