Fix bug 497095 - faulty operations retains the new ctag. r=nomisvai
authorPhilipp Kewisch <mozilla@kewis.ch>
Mon, 24 Jan 2011 20:30:14 +0100
changeset 6995 6e981b8218f74c43e8fd8b0d6899a0c8f57dd9c6
parent 6994 66629a8ec1f5ac3d6809bff1875e9b726c1072d4
child 6996 0c665572476a3247a57ee7dfcf2f0d48e1adf52f
push idunknown
push userunknown
push dateunknown
reviewersnomisvai
bugs497095
Fix bug 497095 - faulty operations retains the new ctag. r=nomisvai
calendar/providers/caldav/calDavCalendar.js
--- a/calendar/providers/caldav/calDavCalendar.js
+++ b/calendar/providers/caldav/calDavCalendar.js
@@ -75,16 +75,17 @@ function calDavCalendar() {
     this.mPathIndex = {};
     this.mAuthScheme = null;
     this.mAuthRealm = null;
     this.mObserver = null;
     this.mFirstRefreshDone = false;
     this.mTargetCalendar = null;
     this.mQueuedQueries = [];
     this.mCtag = null;
+    this.mOldCtag = null;
 
     // By default, support both events and todos.
     this.mGenerallySupportedItemTypes = ["VEVENT", "VTODO"];
     this.mSupportedItemTypes = this.mGenerallySupportedItemTypes.slice(0);
 }
 
 // some shorthand
 const calICalendar = Components.interfaces.calICalendar;
@@ -187,16 +188,17 @@ calDavCalendar.prototype = {
 
     // calIChangeLog interface
     resetLog: function caldav_resetLog() {
         if (this.isCached && this.mTargetCalendar) {
             this.mTargetCalendar.startBatch();
             try {
                 try {
                     this.mCtag = null;
+                    this.mOldCtag = null;
                     this.mTargetCalendar.deleteMetaData("ctag");
                 } catch(e) {
                     cal.ERROR(e);
                 }
                 try {
                     this.mWebdavSyncToken = null;
                     this.mTargetCalendar.deleteMetaData("webdav-sync-token");
                 } catch(e) {
@@ -357,16 +359,17 @@ calDavCalendar.prototype = {
 
     mAuthRealm: null,
 
     mFirstRefreshDone: false,
 
     mQueuedQueries: null,
 
     mCtag: null,
+    mOldCtag: null,
 
     mTargetCalendar: null,
 
     // Contains the last valid synctoken returned
     // from the server with Webdav Sync enabled servers
     mWebdavSyncToken: null,
     // Indicates that the server supports Webdav Sync
     // see: http://tools.ietf.org/html/draft-daboo-webdav-sync
@@ -1011,16 +1014,23 @@ calDavCalendar.prototype = {
      * Notifies the caller that a get request has failed.
      *
      * @param errorMsg           Error message
      * @param aListener          (optional) Listener of the request
      * @param aChangeLogListener (optional)Listener for cached calendars
      */
     notifyGetFailed: function notifyGetFailed(errorMsg, aListener, aChangeLogListener) {
          cal.WARN("CalDAV: Get failed: " + errorMsg);
+
+         // Revert the ctag, since something failed it is no longer valid.
+         this.mCtag = this.mOldCtag;
+         this.mTargetCalendar.setMetaData("ctag", this.mCtag);
+         this.mOldCtag = null;
+
+         // Notify changelog listener
          if (this.isCached && aChangeLogListener) {
              aChangeLogListener.onResult({ status: Components.results.NS_ERROR_FAILURE },
                                          Components.results.NS_ERROR_FAILURE);
          }
 
          // Notify operation listener
          this.notifyOperationComplete(aListener,
                                       Components.results.NS_ERROR_FAILURE,
@@ -1206,16 +1216,17 @@ calDavCalendar.prototype = {
                                                 Components.results.NS_OK);
                 }
                 return;
             }
 
             var ctag = multistatus..CS::getctag.toString();
             if (!ctag.length || ctag != thisCalendar.mCtag) {
                 // ctag mismatch, need to fetch calendar-data
+                thisCalendar.mOldCtag = thisCalendar.mCtag;
                 thisCalendar.mCtag = ctag;
                 thisCalendar.mTargetCalendar.setMetaData("ctag", ctag);
                 thisCalendar.getUpdatedItems(thisCalendar.calendarUri,
                                              aChangeLogListener);
                 if (thisCalendar.verboseLogging()) {
                     cal.LOG("CalDAV: ctag mismatch on refresh, fetching data for " +
                             "calendar " + thisCalendar.name);
 
@@ -1446,16 +1457,17 @@ calDavCalendar.prototype = {
             if (!thisCalendar.mHasWebdavSyncSupport && ctag.length) {
                 // We compare the stored ctag with the one we just got, if
                 // they don't match, we update the items in safeRefresh.
                 if (ctag == thisCalendar.mCtag) {
                     thisCalendar.mFirstRefreshDone = true;
                 }
 
                 thisCalendar.mCtag = ctag;
+                thisCalendar.mOldCtag = null;
                 thisCalendar.mTargetCalendar.setMetaData("ctag", ctag);
                 if (thisCalendar.verboseLogging()) {
                     cal.LOG("CalDAV: initial ctag " + ctag + " for calendar " +
                             thisCalendar.name);
                 }
             }
 
             supportedComponentsXml = multistatus..C::["supported-calendar-component-set"];