Browse files

Syncmanager: fix an issue causing local cache corruption when failing…

… to push.

Due to a logical issue in the code, new journal entries were added to the
local cache after they've been created locally, and not after they've
been added to the server. Under normal circumstances this doesn't pose a
problem, however when pushing to the server fails, the local cache
would have the new entries as if they were saved on the server, causing
the app to think there has been a corruption on the server (as entries
should never be removed from the server) and halt the sync.

This change makes it so the entries are saved to the local cache only
after they've been saved on the server.

Note: this was not spotted until now because it relies on an unfortunate
specific sequence of events. It only happens when creating journal
entries, and when trying to sync them successfully connecting to the
server to fetch the journal list and the content of the journal itself,
and only failing when coming to push the journals.

Many thanks to "359" (this user's preferred alias) for reporting the
issue that resulted in this fix.
  • Loading branch information...
tasn committed May 15, 2017
1 parent 9ffdc6a commit 04e50459d48d5399a419ac72fcf20d841d707513
Showing with 5 additions and 1 deletion.
  1. +5 −1 app/src/main/java/com/etesync/syncadapter/syncadapter/
@@ -271,7 +271,6 @@ protected void applyLocalEntries() throws IOException, ContactsStorageException,"Processing (" + String.valueOf(i) + "/" + strTotal + ") " + entry.toString());
SyncEntry cEntry = SyncEntry.fromJournalEntry(crypto, entry);
persistSyncEntry(entry.getUid(), cEntry);
if (cEntry.isAction(SyncEntry.Actions.DELETE)) {
@@ -335,6 +334,11 @@ protected void pushEntries() throws Exceptions.HttpException, IOException, Conta
if (!localEntries.isEmpty()) {
for (List<JournalEntryManager.Entry> entries : ListUtils.partition(localEntries, MAX_PUSH)) {
journal.create(entries, remoteCTag);
// Persist the entries after they've been pushed
for (JournalEntryManager.Entry entry : entries) {
SyncEntry cEntry = SyncEntry.fromJournalEntry(crypto, entry);
persistSyncEntry(entry.getUid(), cEntry);
remoteCTag = entries.get(entries.size() - 1).getUid();
pushed += entries.size();

0 comments on commit 04e5045

Please sign in to comment.