mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
Fix bug in sync if href changes
This commit is contained in:
parent
3d856749f3
commit
f2a0d07c09
2 changed files with 17 additions and 3 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
import vdirsyncer.exceptions as exceptions
|
||||
from vdirsyncer.storage.base import Item
|
||||
from vdirsyncer.storage.memory import MemoryStorage
|
||||
|
|
@ -336,12 +338,19 @@ def test_moved_href():
|
|||
sync(a, b, status)
|
||||
|
||||
b.items['lol'] = b.items.pop('haha')
|
||||
a.delete = a.update = a.upload = blow_up
|
||||
a.delete = a.update = a.upload = b.delete = b.update = b.upload = blow_up
|
||||
|
||||
sync(a, b, status)
|
||||
assert len(status) == 1
|
||||
assert len(list(a.list())) == len(list(b.list())) == 1
|
||||
assert status['haha'][1]['href'] == 'haha'
|
||||
assert status['haha'][1]['href'] == 'lol'
|
||||
old_status = deepcopy(status)
|
||||
|
||||
# Further sync should be a noop
|
||||
b.get_multi = blow_up
|
||||
sync(a, b, status)
|
||||
assert old_status == status
|
||||
assert len(list(a.list())) == len(list(b.list())) == 1
|
||||
|
||||
|
||||
def test_bogus_etag_change():
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class StorageSyncer(object):
|
|||
things.'''
|
||||
def __init__(self, storage, status):
|
||||
'''
|
||||
:param status: {ident: (href, etag)}
|
||||
:param status: {ident: {'href': href, 'etag': etag}}
|
||||
'''
|
||||
self.storage = storage
|
||||
self.status = status
|
||||
|
|
@ -101,6 +101,11 @@ class StorageSyncer(object):
|
|||
hrefs=[self.idents[ident]['href'],
|
||||
href])
|
||||
|
||||
if ident in self.status:
|
||||
# Necessary if item's href changes.
|
||||
# Otherwise it's a no-op, like `a = a`.
|
||||
self.status[ident]['href'] = props['href']
|
||||
|
||||
for href, etag in self.storage.list():
|
||||
props = {'href': href, 'etag': etag}
|
||||
ident, old_meta = href_to_status.get(href, (None, None))
|
||||
|
|
|
|||
Loading…
Reference in a new issue