rework conflict algorithm to detect more conflict cases

This commit is contained in:
Damien Elmes 2010-07-27 23:19:44 +09:00
parent 24d45cf93c
commit 7f41973972

View file

@ -103,8 +103,8 @@ class Sync(QThread):
# multi-mode setup # multi-mode setup
if deck: if deck:
c = sqlite.connect(deck) c = sqlite.connect(deck)
(syncName, localChanged) = c.execute( (syncName, localMod, localSync) = c.execute(
"select syncName, modified > lastSync from decks").fetchone() "select syncName, modified, lastSync from decks").fetchone()
c.close() c.close()
if not syncName: if not syncName:
return return
@ -113,8 +113,8 @@ class Sync(QThread):
syncName = self.parent.syncName syncName = self.parent.syncName
path = self.parent.deckPath path = self.parent.deckPath
c = sqlite.connect(path) c = sqlite.connect(path)
localChanged = c.execute( (localMod, localSync) = c.execute(
"select modified > lastSync from decks").fetchone()[0] "select modified, lastSync from decks").fetchone()
c.close() c.close()
# ensure deck mods cached # ensure deck mods cached
try: try:
@ -145,9 +145,12 @@ class Sync(QThread):
self.emit(SIGNAL("syncClockOff"), timediff) self.emit(SIGNAL("syncClockOff"), timediff)
return return
# check conflicts # check conflicts
remoteChanged = proxy.hasChanged(syncName) proxy.deckName = syncName
remoteMod = proxy.modified()
remoteSync = proxy._lastSync()
minSync = min(localSync, remoteSync)
self.conflictResolution = None self.conflictResolution = None
if localChanged and remoteChanged: if minSync > 0 and localMod > minSync and remoteMod > minSync:
self.emit(SIGNAL("syncConflicts"), syncName) self.emit(SIGNAL("syncConflicts"), syncName)
while not self.conflictResolution: while not self.conflictResolution:
time.sleep(0.2) time.sleep(0.2)
@ -163,7 +166,6 @@ class Sync(QThread):
self.deck = DeckStorage.Deck(path) self.deck = DeckStorage.Deck(path)
client = SyncClient(self.deck) client = SyncClient(self.deck)
client.setServer(proxy) client.setServer(proxy)
proxy.deckName = syncName
# need to do anything? # need to do anything?
start = time.time() start = time.time()
if client.prepareSync(): if client.prepareSync():