Catch more IdentConflicts

This commit is contained in:
Markus Unterwaditzer 2015-09-18 19:36:34 +02:00
parent 21fb9f43ae
commit e303c907ae

View file

@ -95,6 +95,12 @@ class StorageSyncer(object):
prefetch = {} prefetch = {}
self.idents = {} 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(): for href, etag in self.storage.list():
props = {'href': href, 'etag': etag} props = {'href': href, 'etag': etag}
ident, old_etag = href_to_status.get(href, (None, None)) ident, old_etag = href_to_status.get(href, (None, None))
@ -104,7 +110,7 @@ class StorageSyncer(object):
# In both cases we should prefetch # In both cases we should prefetch
prefetch[href] = props prefetch[href] = props
else: else:
self.idents[ident] = props _store_props(ident, props)
# Prefetch items # Prefetch items
for href, item, etag in (self.storage.get_multi(prefetch) for href, item, etag in (self.storage.get_multi(prefetch)
@ -120,11 +126,7 @@ class StorageSyncer(object):
) )
props['item'] = item props['item'] = item
props['ident'] = ident = item.ident props['ident'] = ident = item.ident
_store_props(ident, props)
if self.idents.setdefault(ident, props) is not props:
raise IdentConflict(storage=self.storage,
hrefs=[self.idents[ident]['href'],
href])
def is_changed(self, ident): def is_changed(self, ident):
_, status_etag = self.status.get(ident, (None, None)) _, status_etag = self.status.get(ident, (None, None))