From 3e5f3f5429980711db8e7370713e5f2f96a3686b Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 20 Feb 2017 14:17:52 +0000 Subject: [PATCH] When applying remote entries, save sync tag after application. --- .../davdroid/syncadapter/SyncManager.java | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java index a12a5a0c..6690973b 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java @@ -229,18 +229,21 @@ abstract public class SyncManager { abstract protected void processSyncEntry(SyncEntry cEntry) throws IOException, ContactsStorageException, CalendarStorageException, InvalidCalendarException; - private void applyEntries(List entries, boolean noDelete) throws CalendarStorageException, InvalidCalendarException, ContactsStorageException, IOException, InterruptedException { - String strTotal = String.valueOf(entries.size()); + protected void applyLocalEntries() throws IOException, ContactsStorageException, CalendarStorageException, Exceptions.HttpException, InvalidCalendarException, InterruptedException { + // FIXME: Need a better strategy + // We re-apply local entries so our changes override whatever was written in the remote. + String strTotal = String.valueOf(localEntries.size()); int i = 0; - for (JournalEntryManager.Entry entry : entries) { - if (Thread.interrupted()) + for (JournalEntryManager.Entry entry : localEntries) { + if (Thread.interrupted()) { throw new InterruptedException(); + } i++; App.log.info("Processing (" + String.valueOf(i) + "/" + strTotal + ") " + entry.toString()); SyncEntry cEntry = SyncEntry.fromJournalEntry(settings.password(), entry); - if (noDelete && cEntry.isAction(SyncEntry.Actions.DELETE)) { + if (cEntry.isAction(SyncEntry.Actions.DELETE)) { continue; } App.log.info("Processing resource for journal entry"); @@ -248,12 +251,6 @@ abstract public class SyncManager { } } - protected void applyLocalEntries() throws IOException, ContactsStorageException, CalendarStorageException, Exceptions.HttpException, InvalidCalendarException, InterruptedException { - // FIXME: Need a better strategy - // We re-apply local entries so our changes override whatever was written in the remote. - applyEntries(localEntries, true); - } - protected void queryCapabilities() throws IOException, CalendarStorageException, ContactsStorageException { } @@ -261,15 +258,30 @@ abstract public class SyncManager { remoteEntries = journal.getEntries(settings.password(), remoteCTag); App.log.info("Fetched " + String.valueOf(remoteEntries.size()) + " entries"); - - if (!remoteEntries.isEmpty()) { - remoteCTag = remoteEntries.get(remoteEntries.size() - 1).getUuid(); - } } protected void applyRemoteEntries() throws IOException, ContactsStorageException, CalendarStorageException, InvalidCalendarException, InterruptedException { // Process new vcards from server - applyEntries(remoteEntries, false); + String strTotal = String.valueOf(remoteEntries.size()); + int i = 0; + + try { + for (JournalEntryManager.Entry entry : remoteEntries) { + if (Thread.interrupted()) { + throw new InterruptedException(); + } + i++; + App.log.info("Processing (" + String.valueOf(i) + "/" + strTotal + ") " + entry.toString()); + + SyncEntry cEntry = SyncEntry.fromJournalEntry(settings.password(), entry); + App.log.info("Processing resource for journal entry"); + processSyncEntry(cEntry); + + remoteCTag = entry.getUuid(); + } + } finally { + saveSyncTag(); + } } protected void pushEntries() throws Exceptions.HttpException, IOException, ContactsStorageException, CalendarStorageException {