From: Daira Hopwood Date: Wed, 4 Nov 2015 15:11:34 +0000 (+0000) Subject: Fix and simplify conflict/overwrite detection. X-Git-Url: https://git.rkrishnan.org/uri?a=commitdiff_plain;h=e2a3b5ff635a731ac65167ad2d71ed9141d455ba;p=tahoe-lafs%2Ftahoe-lafs.git Fix and simplify conflict/overwrite detection. Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/frontends/magic_folder.py b/src/allmydata/frontends/magic_folder.py index 55eb4701..92b91f19 100644 --- a/src/allmydata/frontends/magic_folder.py +++ b/src/allmydata/frontends/magic_folder.py @@ -717,21 +717,20 @@ class Downloader(QueueMixin, WriteFileMixin): raise ConflictError("download failed: already conflicted: %r" % (relpath_u,)) d.addCallback(fail) else: - is_conflict = False + pathinfo = get_pathinfo(abspath_u) + 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: - 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') - 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') + + # See . + is_conflict = ( not pathinfo.exists # 2a + or self._is_upload_pending(relpath_u) # 2c.i. + or (db_entry is None or is_new_file(pathinfo, db_entry)) # 2c.ii. + or (dmd_last_downloaded_uri is None or db_entry.last_uploaded_uri is None + or dmd_last_downloaded_uri != db_entry.last_uploaded_uri) # 2c.iii. + ) + if is_conflict: + self._count('objects_conflicted') if relpath_u.endswith(u"/"): if metadata.get('deleted', False):