]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/frontends/magic_folder.py
Simply conflict detection by removing nested if statements
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / frontends / magic_folder.py
index 93463e7aa958994b5abc5f07476a68fe02b89870..c0c4f051f47dbc0a1db3968514bc71662facaedf 100644 (file)
@@ -505,8 +505,7 @@ class WriteFileMixin(object):
         self._log('renaming deleted file to backup: %s' % (abspath_u,))
         try:
             fileutil.rename_no_overwrite(abspath_u, abspath_u + u'.backup')
-        except IOError:
-            # XXX is this the correct error?
+        except OSError:
             self._log("Already gone: '%s'" % (abspath_u,))
         return abspath_u
 
@@ -536,7 +535,7 @@ class Downloader(QueueMixin, WriteFileMixin):
         files = self._db.get_all_relpaths()
         self._log("all files %s" % files)
 
-        d = self._scan_remote_collective()
+        d = self._scan_remote_collective(scan_self=True)
         d.addBoth(self._logcb, "after _scan_remote_collective 0")
         self._turn_deque()
         return d
@@ -630,7 +629,7 @@ class Downloader(QueueMixin, WriteFileMixin):
         d.addBoth(self._logcb, "end of _scan_remote_dmd")
         return d
 
-    def _scan_remote_collective(self):
+    def _scan_remote_collective(self, scan_self=False):
         self._log("_scan_remote_collective")
         scan_batch = {}  # path -> [(filenode, metadata)]
 
@@ -639,7 +638,7 @@ class Downloader(QueueMixin, WriteFileMixin):
             d2 = defer.succeed(None)
             for dir_name in dirmap:
                 (dirnode, metadata) = dirmap[dir_name]
-                if dirnode.get_readonly_uri() != self._upload_readonly_dircap:
+                if scan_self is True or dirnode.get_readonly_uri() != self._upload_readonly_dircap:
                     d2.addCallback(lambda ign, dir_name=dir_name, dirnode=dirnode:
                                    self._scan_remote_dmd(dir_name, dirnode, scan_batch))
                     def _err(f, dir_name=dir_name):
@@ -709,25 +708,19 @@ class Downloader(QueueMixin, WriteFileMixin):
         else:
             is_conflict = False
             db_entry = self._db.get_db_entry(relpath_u)
+            dmd_last_downloaded_uri = metadata.get('last_downloaded_uri', None)
+            dmd_last_uploaded_uri = metadata.get('last_uploaded_uri', None)
             if db_entry:
-                dmd_last_downloaded_uri = metadata.get('last_downloaded_uri', None)
-                print "metadata %r" % (metadata,)
-                print "<<<<--- if %r != %r" % (dmd_last_downloaded_uri, db_entry.last_downloaded_uri)
                 if dmd_last_downloaded_uri is not None and db_entry.last_downloaded_uri is not None:
                     if dmd_last_downloaded_uri != db_entry.last_downloaded_uri:
                         is_conflict = True
                         self._count('objects_conflicted')
-                else:
-                    dmd_last_uploaded_uri = metadata.get('last_uploaded_uri', None)
-                    print ">>>>  if %r != %r" % (dmd_last_uploaded_uri, db_entry.last_uploaded_uri)
-                    if dmd_last_uploaded_uri is not None and dmd_last_uploaded_uri != db_entry.last_uploaded_uri:
-                        is_conflict = True
-                        self._count('objects_conflicted')
-                    else:
-                        # XXX todo: mark as conflict if file is in pending upload set
-                        if self._is_upload_pending(relpath_u):
-                            is_conflict = True
-                            self._count('objects_conflicted')
+                elif dmd_last_uploaded_uri is not None and dmd_last_uploaded_uri != db_entry.last_uploaded_uri:
+                    is_conflict = True
+                    self._count('objects_conflicted')
+                elif self._is_upload_pending(relpath_u):
+                    is_conflict = True
+                    self._count('objects_conflicted')
 
             if relpath_u.endswith(u"/"):
                 if metadata.get('deleted', False):