OSDN Git Service

Add fix for deleted notes not being removed from the database.
authorRandy Baumgarte <randy@fbn.cx>
Sun, 3 Apr 2011 15:26:40 +0000 (11:26 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Sun, 3 Apr 2011 18:03:27 +0000 (14:03 -0400)
src/cx/fbn/nevernote/threads/SyncRunner.java

index f2e1cae..592b82a 100644 (file)
@@ -474,36 +474,40 @@ public class SyncRunner extends QObject implements Runnable {
                                        logger.log(logger.EXTREME, "Tag expunged");\r
                                        updateSequenceNumber = noteStore.expungeTag(authToken, expunged.get(i).guid);\r
                                        conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
-                                       \r
+                                       conn.getSyncTable().setLastSequenceDate(sequenceDate);\r
+                                       conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
+                                       conn.getDeletedTable().expungeDeletedItem(expunged.get(i).guid, "TAG");                                 \r
                                }\r
                                if      (expunged.get(i).type.equalsIgnoreCase("NOTEBOOK")) {\r
                                        logger.log(logger.EXTREME, "Notebook expunged");\r
                                        updateSequenceNumber = noteStore.expungeNotebook(authToken, expunged.get(i).guid);\r
                                        conn.getSyncTable().setLastSequenceDate(sequenceDate);\r
+                                       conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
+                                       conn.getDeletedTable().expungeDeletedItem(expunged.get(i).guid, "NOTEBOOK");\r
                                }\r
                                if (expunged.get(i).type.equalsIgnoreCase("NOTE")) {\r
                                        logger.log(logger.EXTREME, "Note expunged");\r
                                        updateSequenceNumber = noteStore.deleteNote(authToken, expunged.get(i).guid);\r
                                        refreshNeeded = true;\r
+                                       conn.getSyncTable().setLastSequenceDate(sequenceDate);\r
                                        conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
+                                       conn.getDeletedTable().expungeDeletedItem(expunged.get(i).guid, "NOTE");\r
                                }\r
                                if (expunged.get(i).type.equalsIgnoreCase("SAVEDSEARCH")) {\r
                                        logger.log(logger.EXTREME, "saved search expunged");\r
                                        updateSequenceNumber = noteStore.expungeSearch(authToken, expunged.get(i).guid);\r
                                        conn.getSyncTable().setLastSequenceDate(sequenceDate);\r
+                                       conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);\r
+                                       conn.getDeletedTable().expungeDeletedItem(expunged.get(i).guid, "SAVEDSEARCH");\r
                                }\r
                        } catch (EDAMUserException e) {\r
-                               logger.log(logger.LOW, "EDAM User Excepton in syncExpunged: " +expunged.get(i).guid);\r
-                               logger.log(logger.LOW, e.getStackTrace());\r
-                               error = true;\r
+                               logger.log(logger.LOW, "EDAM User Excepton in syncExpunged: " +expunged.get(i).guid);   // This can happen if we try to delete a deleted note\r
                        } catch (EDAMSystemException e) {\r
                                logger.log(logger.LOW, "EDAM System Excepton in syncExpunged: "+expunged.get(i).guid);\r
                                logger.log(logger.LOW, e.getStackTrace());\r
                                error=true;\r
                        } catch (EDAMNotFoundException e) {\r
                                logger.log(logger.LOW, "EDAM Not Found Excepton in syncExpunged: "+expunged.get(i).guid);\r
-//                             logger.log(logger.LOW, e.getStackTrace());\r
-                               //error=true;\r
                        } catch (TException e) {\r
                                logger.log(logger.LOW, "EDAM TExcepton in syncExpunged: "+expunged.get(i).guid);\r
                                logger.log(logger.LOW, e.getStackTrace());\r
@@ -786,7 +790,15 @@ public class SyncRunner extends QObject implements Runnable {
                        badTagSync.clear();\r
                \r
                Tag enTag = findNextTag();\r
-               while(enTag!=null) {\r
+               \r
+               // This is a hack.  Sometimes this function goes flookey and goes into a \r
+               // perpetual loop.  This causes  NeverNote to flood Evernote's servers.\r
+               // This is a safety valve to prevent unlimited loops.\r
+               int maxCount = conn.getTagTable().getDirty().size()+10;\r
+               int loopCount = 0;\r
+               \r
+               while(enTag!=null && loopCount < maxCount) {\r
+                       loopCount++;\r
                        if (authRefreshNeeded)\r
                                if (!refreshConnection())\r
                                        return;\r
@@ -1910,8 +1922,6 @@ public class SyncRunner extends QObject implements Runnable {
                                        syncRemoteResource(linkedNoteStore, chunk.getResources().get(i), linkedAuthResult.getAuthenticationToken());\r
                                }\r
                                syncRemoteLinkedNotebooks(linkedNoteStore, chunk.getNotebooks(), false, book);\r
-//                             SharedNotebook s = linkedNoteStore.getSharedNotebookByAuth(linkedAuthResult.getAuthenticationToken());\r
-//                             syncLinkedTags(chunk.getTags(), s.getNotebookGuid());\r
                                syncLinkedTags(chunk.getTags(), book.getGuid());\r
                                \r
                                // Go through & signal any notes that have changed so we can refresh the user's view\r
@@ -1922,7 +1932,6 @@ public class SyncRunner extends QObject implements Runnable {
                                for (int i=0; i<chunk.getExpungedLinkedNotebooksSize(); i++) {\r
                                        conn.getLinkedNotebookTable().expungeNotebook(chunk.getExpungedLinkedNotebooks().get(i), false);\r
                                }\r
-                               \r
                                usn = chunk.getChunkHighUSN();\r
                                conn.getLinkedNotebookTable().setLastSequenceDate(book.getGuid(),chunk.getCurrentTime());\r
                                conn.getLinkedNotebookTable().setLastSequenceNumber(book.getGuid(),chunk.getChunkHighUSN());\r
@@ -1938,8 +1947,9 @@ public class SyncRunner extends QObject implements Runnable {
                                logger.log(logger.LOW, e.getMessage());\r
                        } catch (EDAMNotFoundException e) {\r
                                syncError = true;\r
-                               status.message.emit(tr("EDAM NotFoundException synchronizing linked notbook.  See the log for datails."));\r
-                               e.printStackTrace();   /// DELETE OLD NOTEBOOKS HERE\r
+                               status.message.emit(tr("Notebook URL not found. Removing notobook " +book.getShareName()));\r
+                               conn.getNotebookTable().deleteLinkedTags(book.getGuid());\r
+                               conn.getLinkedNotebookTable().expungeNotebook(book.getGuid(), false);\r
                                logger.log(logger.LOW, e.getMessage());\r
                        } catch (TException e) {\r
                                syncError = true;\r