Commit 301ab114 authored by Thomas Lotze's avatar Thomas Lotze

in the download module, fixed the handling of directories that are pointed to...

in the download module, fixed the handling of directories that are pointed to by file-system paths and URLs
parent 7edd3c0c
[buildout]
extends = http://svn.zope.org/repos/main/zopetoolkit/branches/1.0/ztk.cfg
develop = zc.recipe.egg_ .
parts = test oltest py
[versions]
zc.buildout =
[py]
recipe = zc.recipe.egg
eggs = zc.buildout
......
......@@ -118,7 +118,7 @@ class Download(object):
cached_path = os.path.join(cache_dir, cache_key)
self.logger.debug('Searching cache at %s' % cache_dir)
if os.path.isfile(cached_path):
if os.path.exists(cached_path):
is_temp = False
if self.fallback:
try:
......@@ -244,8 +244,11 @@ def locate_at(source, dest):
if dest is None or realpath(dest) == realpath(source):
return source
try:
os.link(source, dest)
except (AttributeError, OSError):
shutil.copyfile(source, dest)
if os.path.isdir(source):
shutil.copytree(source, dest)
else:
try:
os.link(source, dest)
except (AttributeError, OSError):
shutil.copyfile(source, dest)
return dest
......@@ -537,6 +537,25 @@ conversions:
>>> path, is_temp = Download()(server_url+'foo.txt', md5(text).hexdigest())
>>> remove(path)
When "downloading" a directory given by file-system path or ``file:`` URL and
using a download cache at the same time, the cached directory wasn't handled
correctly. Consequently, the cache was defeated and an attempt to cache the
directory a second time broke. This is how it should work:
>>> download = Download(cache=cache)
>>> dirpath = join(server_data, 'some_directory')
>>> mkdir(dirpath)
>>> dest, _ = download(dirpath)
If we now modify the source tree, the second download will produce the
original one from the cache:
>>> mkdir(join(dirpath, 'foo'))
>>> ls(dirpath)
d foo
>>> dest, _ = download(dirpath)
>>> ls(dest)
Clean up
--------
......
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