From ed22764921b2e5bf6a934cf14aa9c5fede804d8e Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Fri, 13 Nov 2015 22:54:26 +0100 Subject: [PATCH] Fix bug during prefetch The idea that prefetching isn't necessary if the other storage can't be written to is wrong, we still need to prefetch for UID-matching --- tests/test_sync.py | 17 +++++++++++++++++ vdirsyncer/sync.py | 8 ++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/test_sync.py b/tests/test_sync.py index 6ea36b6..9c4f3cb 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -41,6 +41,7 @@ def test_missing_status(): def test_missing_status_and_different_items(): a = MemoryStorage() b = MemoryStorage() + status = {} item1 = Item(u'UID:1\nhaha') item2 = Item(u'UID:1\nhoho') @@ -54,6 +55,22 @@ def test_missing_status_and_different_items(): assert_item_equals(item1, a.get('1')[0]) +def test_read_only_and_prefetch(): + a = MemoryStorage() + b = MemoryStorage() + b.read_only = True + + status = {} + item1 = Item(u'UID:1\nhaha') + item2 = Item(u'UID:2\nhoho') + a.upload(item1) + a.upload(item2) + + sync(a, b, status, force_delete=True) + sync(a, b, status, force_delete=True) + + assert list(a.list()) == list(b.list()) == [] + def test_upload_and_update(): a = MemoryStorage(fileext='.a') b = MemoryStorage(fileext='.b') diff --git a/vdirsyncer/sync.py b/vdirsyncer/sync.py index 88df95a..ef66d0c 100644 --- a/vdirsyncer/sync.py +++ b/vdirsyncer/sync.py @@ -87,7 +87,7 @@ class StorageSyncer(object): self.status = status self.idents = None - def prepare_idents(self, other_read_only): + def prepare_idents(self): href_to_status = dict((href, (ident, etag)) for ident, (href, etag) in iteritems(self.status)) @@ -105,7 +105,7 @@ class StorageSyncer(object): props = {'href': href, 'etag': etag} ident, old_etag = href_to_status.get(href, (None, None)) assert etag is not None - if etag != old_etag and not other_read_only: + if etag != old_etag: # Either the item is completely new, or updated # In both cases we should prefetch prefetch[href] = props @@ -165,8 +165,8 @@ def sync(storage_a, storage_b, status, conflict_resolution=None, for ident, (href_a, etag_a, href_b, etag_b) in iteritems(status) )) - a_info.prepare_idents(storage_b.read_only) - b_info.prepare_idents(storage_a.read_only) + a_info.prepare_idents() + b_info.prepare_idents() if bool(a_info.idents) != bool(b_info.idents) \ and status and not force_delete: