From: David Stainton Date: Fri, 31 Jul 2015 17:51:19 +0000 (-0700) Subject: Update magic-folder db after download X-Git-Url: https://git.rkrishnan.org/-?a=commitdiff_plain;h=e25b3395c3769f9b2afec53c7b5a0338f3adcbcd;p=tahoe-lafs%2Ftahoe-lafs.git Update magic-folder db after download --- diff --git a/src/allmydata/frontends/magic_folder.py b/src/allmydata/frontends/magic_folder.py index 4bc6b910..8fd39e84 100644 --- a/src/allmydata/frontends/magic_folder.py +++ b/src/allmydata/frontends/magic_folder.py @@ -8,6 +8,7 @@ from twisted.python.failure import Failure from twisted.python import runtime from twisted.application import service +from allmydata.util import fileutil from allmydata.interfaces import IDirectoryNode from allmydata.util import log from allmydata.util.fileutil import precondition_abspath @@ -402,6 +403,7 @@ class Downloader(QueueMixin): latest version wins. """ v = self._db.get_local_file_version(relpath_u) + print "_should_download path %s local db version %s, remote dmd version %s" % (relpath_u, v, remote_version) return (v is None or v < remote_version) def _get_local_latest(self, path_u): @@ -510,9 +512,18 @@ class Downloader(QueueMixin): (name, file_node, metadata) = item d = file_node.download_best_version() def succeeded(res): - d.addCallback(lambda result: self._write_downloaded_file(name, result)) + def do_update_db(result): + filecap = file_node.get_uri() + s = os.stat(name) + size = s[stat.ST_SIZE] + ctime = s[stat.ST_CTIME] + mtime = s[stat.ST_MTIME] + self._db.did_upload_file(filecap, name, metadata['version'], mtime, ctime, size) + d2 = defer.succeed(res) + d2.addCallback(lambda result: self._write_downloaded_file(name, result)) + d2.addCallback(do_update_db) self._count('objects_downloaded') - return None + return d2 def failed(f): self._log("download failed: %s" % (str(f),)) self._count('objects_download_failed') @@ -525,4 +536,4 @@ class Downloader(QueueMixin): return d def _write_downloaded_file(self, name, file_contents): - print "_write_downloaded_file: no-op." + fileutil.write(name, file_contents)