mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-23 10:40:23 +00:00
Implement creating local directories in downloader.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
parent
dad9b11853
commit
07b80cf669
@ -608,32 +608,35 @@ class Downloader(QueueMixin, WriteFileMixin):
|
|||||||
if now is None:
|
if now is None:
|
||||||
now = time.time()
|
now = time.time()
|
||||||
(relpath_u, file_node, metadata) = item
|
(relpath_u, file_node, metadata) = item
|
||||||
d = file_node.download_best_version()
|
fp = self._get_filepath(relpath_u)
|
||||||
def succeeded(res):
|
abspath_u = unicode_from_filepath(fp)
|
||||||
fp = self._get_filepath(relpath_u)
|
|
||||||
abspath_u = unicode_from_filepath(fp)
|
|
||||||
d2 = defer.succeed(res)
|
|
||||||
d2.addCallback(lambda result: self._write_downloaded_file(abspath_u, result, is_conflict=False))
|
|
||||||
def do_update_db(written_abspath_u):
|
|
||||||
filecap = file_node.get_uri()
|
|
||||||
last_uploaded_uri = metadata.get('last_uploaded_uri', None)
|
|
||||||
last_downloaded_uri = filecap
|
|
||||||
last_downloaded_timestamp = now
|
|
||||||
written_pathinfo = get_pathinfo(written_abspath_u)
|
|
||||||
if not written_pathinfo.exists:
|
|
||||||
raise Exception("downloaded file %s disappeared" % quote_local_unicode_path(written_abspath_u))
|
|
||||||
|
|
||||||
self._db.did_upload_version(relpath_u, metadata['version'], last_uploaded_uri,
|
d = defer.succeed(None)
|
||||||
last_downloaded_uri, last_downloaded_timestamp, written_pathinfo)
|
if relpath_u.endswith(u"/"):
|
||||||
d2.addCallback(do_update_db)
|
self._log("mkdir(%r)" % (abspath_u,))
|
||||||
# XXX handle failure here with addErrback...
|
d.addCallback(lambda ign: fileutil.make_dirs(abspath_u))
|
||||||
|
d.addCallback(lambda ign: abspath_u)
|
||||||
|
else:
|
||||||
|
d.addCallback(lambda ign: file_node.download_best_version())
|
||||||
|
d.addCallback(lambda contents: self._write_downloaded_file(abspath_u, contents, is_conflict=False))
|
||||||
|
|
||||||
|
def do_update_db(written_abspath_u):
|
||||||
|
filecap = file_node.get_uri()
|
||||||
|
last_uploaded_uri = metadata.get('last_uploaded_uri', None)
|
||||||
|
last_downloaded_uri = filecap
|
||||||
|
last_downloaded_timestamp = now
|
||||||
|
written_pathinfo = get_pathinfo(written_abspath_u)
|
||||||
|
if not written_pathinfo.exists:
|
||||||
|
raise Exception("downloaded object %s disappeared" % quote_local_unicode_path(written_abspath_u))
|
||||||
|
|
||||||
|
self._db.did_upload_version(relpath_u, metadata['version'], last_uploaded_uri,
|
||||||
|
last_downloaded_uri, last_downloaded_timestamp, written_pathinfo)
|
||||||
self._count('objects_downloaded')
|
self._count('objects_downloaded')
|
||||||
return d2
|
|
||||||
def failed(f):
|
def failed(f):
|
||||||
self._log("download failed: %s" % (str(f),))
|
self._log("download failed: %s" % (str(f),))
|
||||||
self._count('objects_download_failed')
|
self._count('objects_failed')
|
||||||
return f
|
return f
|
||||||
d.addCallbacks(succeeded, failed)
|
d.addCallbacks(do_update_db, failed)
|
||||||
def remove_from_pending(res):
|
def remove_from_pending(res):
|
||||||
self._pending.remove(relpath_u)
|
self._pending.remove(relpath_u)
|
||||||
return res
|
return res
|
||||||
|
Loading…
x
Reference in New Issue
Block a user