From 14aae4e4ed12e71e1aa705b280962ba4d3d4faf2 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Wed, 30 Nov 2011 21:37:22 +1300 Subject: [PATCH] When we get an error attempt resync with no token. But only try once, otherwise fall back to PROPFIND. --- .../acal/service/SyncCollectionContents.java | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/com/morphoss/acal/service/SyncCollectionContents.java b/src/com/morphoss/acal/service/SyncCollectionContents.java index bb6bbcb..da2af70 100644 --- a/src/com/morphoss/acal/service/SyncCollectionContents.java +++ b/src/com/morphoss/acal/service/SyncCollectionContents.java @@ -91,6 +91,7 @@ public class SyncCollectionContents extends ServiceJob { private AcalRequestor requestor = null; private boolean resourcesWereSynchronized; private boolean syncWasCompleted; + private int errorCounter = 0; /** @@ -190,7 +191,6 @@ public class SyncCollectionContents extends ServiceJob { } cr.update(DavCollections.CONTENT_URI, collectionData, DavCollections._ID + "=?", new String[] { "" + collectionId }); - } if ( resourcesWereSynchronized ) { @@ -346,6 +346,18 @@ public class SyncCollectionContents extends ServiceJob { Log.println(Constants.LOGV,TAG, "Start processing response"); List responses = root.getNodesFromPath("multistatus/response"); if ( responses.isEmpty() ) { + if ( errorCounter == 0 ) { + responses = root.getNodesFromPath("error/valid-sync-token"); + errorCounter++; + + if ( ! responses.isEmpty() ) { + Log.i("aCal","We sent an invalid sync-token. Retrying without a sync-token."); + syncToken = null; + updateCollectionToken(syncToken); + return doRegularSyncPropfind(); + } + } + responses = root.getNodesFromPath("multistatus/sync-response"); if ( ! responses.isEmpty() ) { Log.e("aCal","CalDAV Server at "+requestor.getHostName()+" uses obsolete draft sync-response syntax. Falling back to inefficient PROPFIND. Please upgrade your server."); @@ -362,9 +374,10 @@ public class SyncCollectionContents extends ServiceJob { responses = root.getNodesFromPath("multistatus/sync-token"); if ( responses.isEmpty() ) { Log.i("aCal","No sync-token in sync-report response. Falling back to PROPFIND."); + updateCollectionToken(null); return doRegularSyncPropfind(); } - + } else { @@ -427,6 +440,17 @@ public class SyncCollectionContents extends ServiceJob { } + private void updateCollectionToken(String newToken) { + ContentValues updateData = new ContentValues(); + updateData.put(DavCollections.SYNC_TOKEN, newToken); + if (Constants.LOG_VERBOSE && Constants.debugSyncCollectionContents ) + Log.i(TAG,"Updated collection record with new sync token '"+syncToken+"'"); + + cr.update(DavCollections.CONTENT_URI, collectionData, DavCollections._ID + "=?", + new String[] { "" + collectionId }); + } + + /** *

* Do a sync run using a PROPFIND against the collection and a pass through the DB comparing all resources -- 2.11.4.GIT