Skip to content

Commit

Permalink
Catch more IdentConflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Sep 18, 2015
1 parent 21fb9f4 commit e303c90
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions vdirsyncer/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def prepare_idents(self, other_read_only):
prefetch = {}
self.idents = {}

def _store_props(ident, props):
if self.idents.setdefault(ident, props) is not props:
raise IdentConflict(storage=self.storage,
hrefs=[self.idents[ident]['href'],
href])

for href, etag in self.storage.list():
props = {'href': href, 'etag': etag}
ident, old_etag = href_to_status.get(href, (None, None))
Expand All @@ -104,7 +110,7 @@ def prepare_idents(self, other_read_only):
# In both cases we should prefetch
prefetch[href] = props
else:
self.idents[ident] = props
_store_props(ident, props)

# Prefetch items
for href, item, etag in (self.storage.get_multi(prefetch)
Expand All @@ -120,11 +126,7 @@ def prepare_idents(self, other_read_only):
)
props['item'] = item
props['ident'] = ident = item.ident

if self.idents.setdefault(ident, props) is not props:
raise IdentConflict(storage=self.storage,
hrefs=[self.idents[ident]['href'],
href])
_store_props(ident, props)

def is_changed(self, ident):
_, status_etag = self.status.get(ident, (None, None))
Expand Down

0 comments on commit e303c90

Please sign in to comment.