]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Capture exceptions from conflict and write info in magic folder db
authorDavid Stainton <dstainton415@gmail.com>
Wed, 26 Aug 2015 14:50:35 +0000 (16:50 +0200)
committerDavid Stainton <dstainton415@gmail.com>
Wed, 26 Aug 2015 14:50:35 +0000 (16:50 +0200)
src/allmydata/frontends/magic_folder.py

index e4e9cf3724fbca0e8e976b32f4e064a48a52e386..bee6fc715aa34b0d07331b95cb04d8d802438c25 100644 (file)
@@ -518,9 +518,15 @@ class Downloader(QueueMixin):
         (name, file_node, metadata) = item
         d = file_node.download_best_version()
         def succeeded(res):
-            def do_update_db(result):
+            def do_update_db(result, is_conflicted=False):
                 filecap = file_node.get_uri()
-                s = os.stat(name)
+                full_path = fileutil.abspath_expanduser_unicode(name, base=self._local_path_u)
+                if is_conflicted:
+                    full_path = full_path + u".conflict" # XXX do we want to mark the conflicted in the db???
+                try:
+                    s = os.stat(full_path)
+                except:
+                    raise(Exception("wtf downloaded file %s disappeared" % full_path))
                 size = s[stat.ST_SIZE]
                 ctime = s[stat.ST_CTIME]
                 mtime = s[stat.ST_MTIME]
@@ -528,6 +534,7 @@ class Downloader(QueueMixin):
             d2 = defer.succeed(res)
             d2.addCallback(lambda result: self._write_downloaded_file(name, result, self._local_path_u))
             d2.addCallback(do_update_db)
+            d2.addErrback(lambda x: do_update_db(x, is_conflicted=True))
             self._count('objects_downloaded')
             return d2
         def failed(f):
@@ -568,7 +575,10 @@ class Downloader(QueueMixin):
             try:
                 fileutil.replace_file(path, replacement_path, backup_path)
             except fileutil.ConflictError:
+                is_conflict = True
                 cls._rename_conflicted_file(path, replacement_path)
+        if is_conflict:
+            raise(Exception("Conflict detected..."))
 
     @classmethod
     def _rename_conflicted_file(self, path, replacement_path):