[CalendarServer-changes] [14554] CalendarServer/branches/release/CalendarServer-6.1-dev

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 10 09:58:24 PDT 2015


Revision: 14554
          http://trac.calendarserver.org//changeset/14554
Author:   wsanchez at apple.com
Date:     2015-03-10 09:58:24 -0700 (Tue, 10 Mar 2015)
Log Message:
-----------
Pulled up r14492 from trunk

Revision Links:
--------------
    http://trac.calendarserver.org//changeset/14492

Modified Paths:
--------------
    CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/caldav/datastore/test/test_sql.py
    CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/carddav/datastore/sql.py
    CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/carddav/datastore/test/test_sql.py
    CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/common/datastore/sql.py
    CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/common/datastore/test/test_sql.py

Property Changed:
----------------
    CalendarServer/branches/release/CalendarServer-6.1-dev/


Property changes on: CalendarServer/branches/release/CalendarServer-6.1-dev
___________________________________________________________________
Modified: svn:mergeinfo
   - /CalDAVTester/trunk:11193-11198
/CalendarServer/branches/config-separation:4379-4443
/CalendarServer/branches/egg-info-351:4589-4625
/CalendarServer/branches/generic-sqlstore:6167-6191
/CalendarServer/branches/new-store:5594-5934
/CalendarServer/branches/new-store-no-caldavfile:5911-5935
/CalendarServer/branches/new-store-no-caldavfile-2:5936-5981
/CalendarServer/branches/release/CalendarServer-4.3-dev:10180-10190,10192
/CalendarServer/branches/release/CalendarServer-5.1-dev:11846
/CalendarServer/branches/release/CalendarServer-5.2-dev:11972,12357-12358,12794,12814
/CalendarServer/branches/users/cdaboo/batchupload-6699:6700-7198
/CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692:5693-5702
/CalendarServer/branches/users/cdaboo/component-set-fixes:8130-8346
/CalendarServer/branches/users/cdaboo/cross-pod-sharing:12038-12191
/CalendarServer/branches/users/cdaboo/directory-cache-on-demand-3627:3628-3644
/CalendarServer/branches/users/cdaboo/fix-no-ischedule:11607-11871
/CalendarServer/branches/users/cdaboo/implicituidrace:8137-8141
/CalendarServer/branches/users/cdaboo/ischedule-dkim:9747-9979
/CalendarServer/branches/users/cdaboo/json:11622-11912
/CalendarServer/branches/users/cdaboo/managed-attachments:9985-10145
/CalendarServer/branches/users/cdaboo/more-sharing-5591:5592-5601
/CalendarServer/branches/users/cdaboo/partition-4464:4465-4957
/CalendarServer/branches/users/cdaboo/performance-tweaks:11824-11836
/CalendarServer/branches/users/cdaboo/pods:7297-7377
/CalendarServer/branches/users/cdaboo/pycalendar:7085-7206
/CalendarServer/branches/users/cdaboo/pycard:7227-7237
/CalendarServer/branches/users/cdaboo/queued-attendee-refreshes:7740-8287
/CalendarServer/branches/users/cdaboo/relative-config-paths-5070:5071-5105
/CalendarServer/branches/users/cdaboo/reverse-proxy-pods:11875-11900
/CalendarServer/branches/users/cdaboo/scheduling-queue-refresh:11783-12557
/CalendarServer/branches/users/cdaboo/shared-calendars-5187:5188-5440
/CalendarServer/branches/users/cdaboo/sharing-in-the-store:11935-12016
/CalendarServer/branches/users/cdaboo/store-scheduling:10876-11129
/CalendarServer/branches/users/cdaboo/timezones:7443-7699
/CalendarServer/branches/users/cdaboo/txn-debugging:8730-8743
/CalendarServer/branches/users/gaya/cleanrevisions:12152-12334
/CalendarServer/branches/users/gaya/groupsharee2:13669-13773
/CalendarServer/branches/users/gaya/sharedgroupfixes:12120-12142
/CalendarServer/branches/users/gaya/sharedgroups-3:11088-11204
/CalendarServer/branches/users/glyph/always-abort-txn-on-error:9958-9969
/CalendarServer/branches/users/glyph/case-insensitive-uid:8772-8805
/CalendarServer/branches/users/glyph/conn-limit:6574-6577
/CalendarServer/branches/users/glyph/contacts-server-merge:4971-5080
/CalendarServer/branches/users/glyph/dalify:6932-7023
/CalendarServer/branches/users/glyph/db-reconnect:6824-6876
/CalendarServer/branches/users/glyph/deploybuild:7563-7572
/CalendarServer/branches/users/glyph/digest-auth-redux:10624-10635
/CalendarServer/branches/users/glyph/disable-quota:7718-7727
/CalendarServer/branches/users/glyph/dont-start-postgres:6592-6614
/CalendarServer/branches/users/glyph/enforce-max-requests:11640-11643
/CalendarServer/branches/users/glyph/hang-fix:11465-11491
/CalendarServer/branches/users/glyph/imip-and-admin-html:7866-7984
/CalendarServer/branches/users/glyph/ipv6-client:9054-9105
/CalendarServer/branches/users/glyph/launchd-wrapper-bis:11413-11436
/CalendarServer/branches/users/glyph/linux-tests:6893-6900
/CalendarServer/branches/users/glyph/log-cleanups:11691-11731
/CalendarServer/branches/users/glyph/migrate-merge:8690-8713
/CalendarServer/branches/users/glyph/misc-portability-fixes:7365-7374
/CalendarServer/branches/users/glyph/more-deferreds-6:6322-6368
/CalendarServer/branches/users/glyph/more-deferreds-7:6369-6445
/CalendarServer/branches/users/glyph/multiget-delete:8321-8330
/CalendarServer/branches/users/glyph/new-export:7444-7485
/CalendarServer/branches/users/glyph/one-home-list-api:10048-10073
/CalendarServer/branches/users/glyph/oracle:7106-7155
/CalendarServer/branches/users/glyph/oracle-nulls:7340-7351
/CalendarServer/branches/users/glyph/other-html:8062-8091
/CalendarServer/branches/users/glyph/parallel-sim:8240-8251
/CalendarServer/branches/users/glyph/parallel-upgrade:8376-8400
/CalendarServer/branches/users/glyph/parallel-upgrade_to_1:8571-8583
/CalendarServer/branches/users/glyph/q:9560-9688
/CalendarServer/branches/users/glyph/queue-locking-and-timing:10204-10289
/CalendarServer/branches/users/glyph/quota:7604-7637
/CalendarServer/branches/users/glyph/sendfdport:5388-5424
/CalendarServer/branches/users/glyph/shared-pool-fixes:8436-8443
/CalendarServer/branches/users/glyph/shared-pool-take2:8155-8174
/CalendarServer/branches/users/glyph/sharedpool:6490-6550
/CalendarServer/branches/users/glyph/sharing-api:9192-9205
/CalendarServer/branches/users/glyph/skip-lonely-vtimezones:8524-8535
/CalendarServer/branches/users/glyph/sql-store:5929-6073
/CalendarServer/branches/users/glyph/start-service-start-loop:11060-11065
/CalendarServer/branches/users/glyph/subtransactions:7248-7258
/CalendarServer/branches/users/glyph/table-alias:8651-8664
/CalendarServer/branches/users/glyph/uidexport:7673-7676
/CalendarServer/branches/users/glyph/unshare-when-access-revoked:10562-10595
/CalendarServer/branches/users/glyph/use-system-twisted:5084-5149
/CalendarServer/branches/users/glyph/uuid-normalize:9268-9296
/CalendarServer/branches/users/glyph/warning-cleanups:11347-11357
/CalendarServer/branches/users/glyph/whenNotProposed:11881-11897
/CalendarServer/branches/users/glyph/xattrs-from-files:7757-7769
/CalendarServer/branches/users/sagen/applepush:8126-8184
/CalendarServer/branches/users/sagen/inboxitems:7380-7381
/CalendarServer/branches/users/sagen/locations-resources:5032-5051
/CalendarServer/branches/users/sagen/locations-resources-2:5052-5061
/CalendarServer/branches/users/sagen/move2who:12819-12860
/CalendarServer/branches/users/sagen/move2who-2:12861-12898
/CalendarServer/branches/users/sagen/move2who-3:12899-12913
/CalendarServer/branches/users/sagen/move2who-4:12914-13157
/CalendarServer/branches/users/sagen/move2who-5:13158-13163
/CalendarServer/branches/users/sagen/newcua:13309-13327
/CalendarServer/branches/users/sagen/newcua-1:13328-13330
/CalendarServer/branches/users/sagen/purge_old_events:6735-6746
/CalendarServer/branches/users/sagen/recordtypes:13648-13656
/CalendarServer/branches/users/sagen/recordtypes-2:13657
/CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
/CalendarServer/branches/users/sagen/resources-2:5084-5093
/CalendarServer/branches/users/sagen/testing:10827-10851,10853-10855
/CalendarServer/branches/users/wsanchez/transations:5515-5593
/CalendarServer/trunk:14469
   + /CalDAVTester/trunk:11193-11198
/CalendarServer/branches/config-separation:4379-4443
/CalendarServer/branches/egg-info-351:4589-4625
/CalendarServer/branches/generic-sqlstore:6167-6191
/CalendarServer/branches/new-store:5594-5934
/CalendarServer/branches/new-store-no-caldavfile:5911-5935
/CalendarServer/branches/new-store-no-caldavfile-2:5936-5981
/CalendarServer/branches/release/CalendarServer-4.3-dev:10180-10190,10192
/CalendarServer/branches/release/CalendarServer-5.1-dev:11846
/CalendarServer/branches/release/CalendarServer-5.2-dev:11972,12357-12358,12794,12814
/CalendarServer/branches/users/cdaboo/batchupload-6699:6700-7198
/CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692:5693-5702
/CalendarServer/branches/users/cdaboo/component-set-fixes:8130-8346
/CalendarServer/branches/users/cdaboo/cross-pod-sharing:12038-12191
/CalendarServer/branches/users/cdaboo/directory-cache-on-demand-3627:3628-3644
/CalendarServer/branches/users/cdaboo/fix-no-ischedule:11607-11871
/CalendarServer/branches/users/cdaboo/implicituidrace:8137-8141
/CalendarServer/branches/users/cdaboo/ischedule-dkim:9747-9979
/CalendarServer/branches/users/cdaboo/json:11622-11912
/CalendarServer/branches/users/cdaboo/managed-attachments:9985-10145
/CalendarServer/branches/users/cdaboo/more-sharing-5591:5592-5601
/CalendarServer/branches/users/cdaboo/partition-4464:4465-4957
/CalendarServer/branches/users/cdaboo/performance-tweaks:11824-11836
/CalendarServer/branches/users/cdaboo/pods:7297-7377
/CalendarServer/branches/users/cdaboo/pycalendar:7085-7206
/CalendarServer/branches/users/cdaboo/pycard:7227-7237
/CalendarServer/branches/users/cdaboo/queued-attendee-refreshes:7740-8287
/CalendarServer/branches/users/cdaboo/relative-config-paths-5070:5071-5105
/CalendarServer/branches/users/cdaboo/reverse-proxy-pods:11875-11900
/CalendarServer/branches/users/cdaboo/scheduling-queue-refresh:11783-12557
/CalendarServer/branches/users/cdaboo/shared-calendars-5187:5188-5440
/CalendarServer/branches/users/cdaboo/sharing-in-the-store:11935-12016
/CalendarServer/branches/users/cdaboo/store-scheduling:10876-11129
/CalendarServer/branches/users/cdaboo/timezones:7443-7699
/CalendarServer/branches/users/cdaboo/txn-debugging:8730-8743
/CalendarServer/branches/users/gaya/cleanrevisions:12152-12334
/CalendarServer/branches/users/gaya/groupsharee2:13669-13773
/CalendarServer/branches/users/gaya/sharedgroupfixes:12120-12142
/CalendarServer/branches/users/gaya/sharedgroups-3:11088-11204
/CalendarServer/branches/users/glyph/always-abort-txn-on-error:9958-9969
/CalendarServer/branches/users/glyph/case-insensitive-uid:8772-8805
/CalendarServer/branches/users/glyph/conn-limit:6574-6577
/CalendarServer/branches/users/glyph/contacts-server-merge:4971-5080
/CalendarServer/branches/users/glyph/dalify:6932-7023
/CalendarServer/branches/users/glyph/db-reconnect:6824-6876
/CalendarServer/branches/users/glyph/deploybuild:7563-7572
/CalendarServer/branches/users/glyph/digest-auth-redux:10624-10635
/CalendarServer/branches/users/glyph/disable-quota:7718-7727
/CalendarServer/branches/users/glyph/dont-start-postgres:6592-6614
/CalendarServer/branches/users/glyph/enforce-max-requests:11640-11643
/CalendarServer/branches/users/glyph/hang-fix:11465-11491
/CalendarServer/branches/users/glyph/imip-and-admin-html:7866-7984
/CalendarServer/branches/users/glyph/ipv6-client:9054-9105
/CalendarServer/branches/users/glyph/launchd-wrapper-bis:11413-11436
/CalendarServer/branches/users/glyph/linux-tests:6893-6900
/CalendarServer/branches/users/glyph/log-cleanups:11691-11731
/CalendarServer/branches/users/glyph/migrate-merge:8690-8713
/CalendarServer/branches/users/glyph/misc-portability-fixes:7365-7374
/CalendarServer/branches/users/glyph/more-deferreds-6:6322-6368
/CalendarServer/branches/users/glyph/more-deferreds-7:6369-6445
/CalendarServer/branches/users/glyph/multiget-delete:8321-8330
/CalendarServer/branches/users/glyph/new-export:7444-7485
/CalendarServer/branches/users/glyph/one-home-list-api:10048-10073
/CalendarServer/branches/users/glyph/oracle:7106-7155
/CalendarServer/branches/users/glyph/oracle-nulls:7340-7351
/CalendarServer/branches/users/glyph/other-html:8062-8091
/CalendarServer/branches/users/glyph/parallel-sim:8240-8251
/CalendarServer/branches/users/glyph/parallel-upgrade:8376-8400
/CalendarServer/branches/users/glyph/parallel-upgrade_to_1:8571-8583
/CalendarServer/branches/users/glyph/q:9560-9688
/CalendarServer/branches/users/glyph/queue-locking-and-timing:10204-10289
/CalendarServer/branches/users/glyph/quota:7604-7637
/CalendarServer/branches/users/glyph/sendfdport:5388-5424
/CalendarServer/branches/users/glyph/shared-pool-fixes:8436-8443
/CalendarServer/branches/users/glyph/shared-pool-take2:8155-8174
/CalendarServer/branches/users/glyph/sharedpool:6490-6550
/CalendarServer/branches/users/glyph/sharing-api:9192-9205
/CalendarServer/branches/users/glyph/skip-lonely-vtimezones:8524-8535
/CalendarServer/branches/users/glyph/sql-store:5929-6073
/CalendarServer/branches/users/glyph/start-service-start-loop:11060-11065
/CalendarServer/branches/users/glyph/subtransactions:7248-7258
/CalendarServer/branches/users/glyph/table-alias:8651-8664
/CalendarServer/branches/users/glyph/uidexport:7673-7676
/CalendarServer/branches/users/glyph/unshare-when-access-revoked:10562-10595
/CalendarServer/branches/users/glyph/use-system-twisted:5084-5149
/CalendarServer/branches/users/glyph/uuid-normalize:9268-9296
/CalendarServer/branches/users/glyph/warning-cleanups:11347-11357
/CalendarServer/branches/users/glyph/whenNotProposed:11881-11897
/CalendarServer/branches/users/glyph/xattrs-from-files:7757-7769
/CalendarServer/branches/users/sagen/applepush:8126-8184
/CalendarServer/branches/users/sagen/inboxitems:7380-7381
/CalendarServer/branches/users/sagen/locations-resources:5032-5051
/CalendarServer/branches/users/sagen/locations-resources-2:5052-5061
/CalendarServer/branches/users/sagen/move2who:12819-12860
/CalendarServer/branches/users/sagen/move2who-2:12861-12898
/CalendarServer/branches/users/sagen/move2who-3:12899-12913
/CalendarServer/branches/users/sagen/move2who-4:12914-13157
/CalendarServer/branches/users/sagen/move2who-5:13158-13163
/CalendarServer/branches/users/sagen/newcua:13309-13327
/CalendarServer/branches/users/sagen/newcua-1:13328-13330
/CalendarServer/branches/users/sagen/purge_old_events:6735-6746
/CalendarServer/branches/users/sagen/recordtypes:13648-13656
/CalendarServer/branches/users/sagen/recordtypes-2:13657
/CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
/CalendarServer/branches/users/sagen/resources-2:5084-5093
/CalendarServer/branches/users/sagen/testing:10827-10851,10853-10855
/CalendarServer/branches/users/wsanchez/transations:5515-5593
/CalendarServer/trunk:14469,14492

Modified: CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/caldav/datastore/test/test_sql.py	2015-03-10 16:57:02 UTC (rev 14553)
+++ CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/caldav/datastore/test/test_sql.py	2015-03-10 16:58:24 UTC (rev 14554)
@@ -2223,7 +2223,37 @@
         yield self.commit()
 
 
+    @inlineCallbacks
+    def test_removeAfterRevisionCleanup(self):
+        """
+        Make sure L{Calendar}'s can be renamed after revision cleanup
+        removes their revision table entry..
+        """
+        yield self.homeUnderTest(name="user01", create=True)
+        cal = yield self.calendarUnderTest(home="user01", name="calendar")
+        self.assertTrue(cal is not None)
+        yield self.commit()
 
+        # Remove the revision
+        cal = yield self.calendarUnderTest(home="user01", name="calendar")
+        yield cal.syncToken()
+        yield self.transactionUnderTest().deleteRevisionsBefore(cal._syncTokenRevision + 1)
+        yield self.commit()
+
+        # Rename the calendar
+        cal = yield self.calendarUnderTest(home="user01", name="calendar")
+        self.assertTrue(cal is not None)
+        yield cal.rename("calendar_renamed")
+        yield self.commit()
+
+        cal = yield self.calendarUnderTest(home="user01", name="calendar")
+        self.assertTrue(cal is None)
+        cal = yield self.calendarUnderTest(home="user01", name="calendar_renamed")
+        self.assertTrue(cal is not None)
+        yield self.commit()
+
+
+
 class SchedulingTests(CommonCommonTests, unittest.TestCase):
     """
     CalendarObject splitting tests

Modified: CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/carddav/datastore/sql.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/carddav/datastore/sql.py	2015-03-10 16:57:02 UTC (rev 14553)
+++ CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/carddav/datastore/sql.py	2015-03-10 16:58:24 UTC (rev 14554)
@@ -602,6 +602,14 @@
                     self._txn, resourceID=self._resourceID, name=name, id=id))
             if rows:
                 self._syncTokenRevision = rows[0][0]
+            else:
+                # Nothing was matched on the delete so insert a new row
+                self._syncTokenRevision = (
+                    yield self._completelyNewDeletedRevisionQuery.on(
+                        self._txn, homeID=self.ownerHome()._resourceID,
+                        resourceID=self._resourceID, name=name)
+                )[0][0]
+
         elif action == "update":
             rows = (
                 yield self._updateBumpTokenQuery.on(
@@ -609,9 +617,14 @@
             if rows:
                 self._syncTokenRevision = rows[0][0]
             else:
-                action = "insert"
+                # Nothing was matched on the update so insert a new row
+                self._syncTokenRevision = (
+                    yield self._completelyNewRevisionQuery.on(
+                        self._txn, homeID=self.ownerHome()._resourceID,
+                        resourceID=self._resourceID, name=name)
+                )[0][0]
 
-        if action == "insert":
+        elif action == "insert":
             # Note that an "insert" may happen for a resource that previously
             # existed and then was deleted. In that case an entry in the
             # REVISIONS table still exists so we have to detect that and do db

Modified: CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/carddav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/carddav/datastore/test/test_sql.py	2015-03-10 16:57:02 UTC (rev 14553)
+++ CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/carddav/datastore/test/test_sql.py	2015-03-10 16:58:24 UTC (rev 14554)
@@ -911,3 +911,119 @@
         obj = yield self.addressbookObjectUnderTest(name="data1.ics", addressbook_name="addressbook")
         self.assertEqual(obj._dataversion, obj._currentDataVersion)
         yield self.commit()
+
+
+    @inlineCallbacks
+    def test_updateAfterRevisionCleanup(self):
+        """
+        Make sure L{AddressBookObject}'s can be updated or removed after revision cleanup
+        removes their revision table entry..
+        """
+        person = """BEGIN:VCARD
+VERSION:3.0
+N:Thompson;Default1;;;
+FN:Default1 Thompson
+EMAIL;type=INTERNET;type=WORK;type=pref:lthompson1 at example.com
+TEL;type=WORK;type=pref:1-555-555-5555
+TEL;type=CELL:1-444-444-4444
+item1.ADR;type=WORK;type=pref:;;1245 Test;Sesame Street;California;11111;USA
+item1.X-ABADR:us
+UID:uid-person
+X-ADDRESSBOOKSERVER-KIND:person
+END:VCARD
+"""
+        group = """BEGIN:VCARD
+VERSION:3.0
+N:Group;Fancy;;;
+FN:Fancy Group
+UID:uid-group
+X-ADDRESSBOOKSERVER-KIND:group
+X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:uid-person
+END:VCARD
+"""
+        group_update = """BEGIN:VCARD
+VERSION:3.0
+N:Group2;Fancy;;;
+FN:Fancy Group2
+UID:uid-group
+X-ADDRESSBOOKSERVER-KIND:group
+X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:uid-person
+END:VCARD
+"""
+
+        yield self.homeUnderTest()
+        adbk = yield self.addressbookUnderTest(name="addressbook")
+        yield adbk.createAddressBookObjectWithName("person.vcf", VCard.fromString(person))
+        yield adbk.createAddressBookObjectWithName("group.vcf", VCard.fromString(group))
+        yield self.commit()
+
+        # Remove the revision
+        adbk = yield self.addressbookUnderTest(name="addressbook")
+        yield adbk.syncToken()
+        yield self.transactionUnderTest().deleteRevisionsBefore(adbk._syncTokenRevision + 1)
+        yield self.commit()
+
+        # Update the object
+        obj = yield self.addressbookObjectUnderTest(name="group.vcf", addressbook_name="addressbook")
+        yield obj.setComponent(VCard.fromString(group_update))
+        yield self.commit()
+
+        obj = yield self.addressbookObjectUnderTest(name="group.vcf", addressbook_name="addressbook")
+        self.assertTrue(obj is not None)
+        obj = yield self.addressbookObjectUnderTest(name="person.vcf", addressbook_name="addressbook")
+        self.assertTrue(obj is not None)
+        yield self.commit()
+
+
+    @inlineCallbacks
+    def test_removeAfterRevisionCleanup(self):
+        """
+        Make sure L{AddressBookObject}'s can be updated or removed after revision cleanup
+        removes their revision table entry..
+        """
+        person = """BEGIN:VCARD
+VERSION:3.0
+N:Thompson;Default1;;;
+FN:Default1 Thompson
+EMAIL;type=INTERNET;type=WORK;type=pref:lthompson1 at example.com
+TEL;type=WORK;type=pref:1-555-555-5555
+TEL;type=CELL:1-444-444-4444
+item1.ADR;type=WORK;type=pref:;;1245 Test;Sesame Street;California;11111;USA
+item1.X-ABADR:us
+UID:uid-person
+X-ADDRESSBOOKSERVER-KIND:person
+END:VCARD
+"""
+        group = """BEGIN:VCARD
+VERSION:3.0
+N:Group;Fancy;;;
+FN:Fancy Group
+UID:uid-group
+X-ADDRESSBOOKSERVER-KIND:group
+X-ADDRESSBOOKSERVER-MEMBER:urn:uuid:uid-person
+END:VCARD
+"""
+
+        yield self.homeUnderTest()
+        adbk = yield self.addressbookUnderTest(name="addressbook")
+        yield adbk.createAddressBookObjectWithName("person.vcf", VCard.fromString(person))
+        yield adbk.createAddressBookObjectWithName("group.vcf", VCard.fromString(group))
+        yield self.commit()
+
+        # Remove the revision
+        adbk = yield self.addressbookUnderTest(name="addressbook")
+        yield adbk.syncToken()
+        yield self.transactionUnderTest().deleteRevisionsBefore(adbk._syncTokenRevision + 1)
+        yield self.commit()
+
+        # Remove the object
+        obj = yield self.addressbookObjectUnderTest(name="group.vcf", addressbook_name="addressbook")
+        self.assertTrue(obj is not None)
+        yield obj.remove()
+        yield self.commit()
+
+        obj = yield self.addressbookObjectUnderTest(name="group.vcf", addressbook_name="addressbook")
+        self.assertTrue(obj is None)
+        obj = yield self.addressbookObjectUnderTest(name="person.vcf", addressbook_name="addressbook")
+        self.assertTrue(obj is not None)
+        yield self.commit()

Modified: CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/common/datastore/sql.py	2015-03-10 16:57:02 UTC (rev 14553)
+++ CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/common/datastore/sql.py	2015-03-10 16:58:24 UTC (rev 14554)
@@ -4259,9 +4259,13 @@
 
     @inlineCallbacks
     def _renameSyncToken(self):
-        self._syncTokenRevision = (yield self._renameSyncTokenQuery.on(
-            self._txn, name=self._name, resourceID=self._resourceID))[0][0]
-        self._txn.bumpRevisionForObject(self)
+        rows = yield self._renameSyncTokenQuery.on(
+            self._txn, name=self._name, resourceID=self._resourceID)
+        if rows:
+            self._syncTokenRevision = rows[0][0]
+            self._txn.bumpRevisionForObject(self)
+        else:
+            yield self._initSyncToken()
 
 
     @classproperty
@@ -4440,6 +4444,21 @@
         )
 
 
+    @classproperty
+    def _completelyNewDeletedRevisionQuery(cls):
+        rev = cls._revisionsSchema
+        return Insert(
+            {
+                rev.HOME_RESOURCE_ID: Parameter("homeID"),
+                rev.RESOURCE_ID: Parameter("resourceID"),
+                rev.RESOURCE_NAME: Parameter("name"),
+                rev.REVISION: schema.REVISION_SEQ,
+                rev.DELETED: True
+            },
+            Return=rev.REVISION
+        )
+
+
     @inlineCallbacks
     def _changeRevision(self, action, name):
 
@@ -4452,6 +4471,13 @@
                     self._txn, resourceID=self._resourceID, name=name))
             if rows:
                 self._syncTokenRevision = rows[0][0]
+            else:
+                self._syncTokenRevision = (
+                    yield self._completelyNewDeletedRevisionQuery.on(
+                        self._txn, homeID=self.ownerHome()._resourceID,
+                        resourceID=self._resourceID, name=name)
+                )[0][0]
+
         elif action == "update":
             rows = (
                 yield self._updateBumpTokenQuery.on(
@@ -4459,9 +4485,13 @@
             if rows:
                 self._syncTokenRevision = rows[0][0]
             else:
-                action = "insert"
+                self._syncTokenRevision = (
+                    yield self._completelyNewRevisionQuery.on(
+                        self._txn, homeID=self.ownerHome()._resourceID,
+                        resourceID=self._resourceID, name=name)
+                )[0][0]
 
-        if action == "insert":
+        elif action == "insert":
             # Note that an "insert" may happen for a resource that previously
             # existed and then was deleted. In that case an entry in the
             # REVISIONS table still exists so we have to detect that and do db

Modified: CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/common/datastore/test/test_sql.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/common/datastore/test/test_sql.py	2015-03-10 16:57:02 UTC (rev 14553)
+++ CalendarServer/branches/release/CalendarServer-6.1-dev/txdav/common/datastore/test/test_sql.py	2015-03-10 16:58:24 UTC (rev 14554)
@@ -337,7 +337,7 @@
         token = yield homeChild.syncToken()
         yield homeChild._changeRevision("delete", "E")
         changed = yield homeChild.resourceNamesSinceToken(token)
-        self.assertEqual(changed, ([], [], [],))
+        self.assertEqual(changed, ([], ["E"], [],))
 
         yield txn.abort()
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150310/1d95577c/attachment-0001.html>


More information about the calendarserver-changes mailing list