[CalendarServer-changes] [12727] CalendarServer/branches/release/CalendarServer-5.2-dev

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:20:57 PDT 2014


Revision: 12727
          http://trac.calendarserver.org//changeset/12727
Author:   cdaboo at apple.com
Date:     2014-02-19 13:41:20 -0800 (Wed, 19 Feb 2014)
Log Message:
-----------
Do not do in-place conversion of dropbox attachments to managed attachments. Instead leave them as dropbox and allow access to them in the normal way when managed attachments are enabled.

Modified Paths:
--------------
    CalendarServer/branches/release/CalendarServer-5.2-dev/twistedcaldav/storebridge.py
    CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/others/attachment_migration.py
    CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/others/test/test_attachment_migration.py

Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.2-dev/twistedcaldav/storebridge.py	2014-02-19 20:02:12 UTC (rev 12726)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/twistedcaldav/storebridge.py	2014-02-19 21:41:20 UTC (rev 12727)
@@ -1714,7 +1714,9 @@
         if calendarObject:
             l = (yield calendarObject.managedAttachmentList())
             if len(l) == 0:
-                calendarObject = None
+                l = (yield calendarObject.attachments())
+                if len(l) == 0:
+                    calendarObject = None
 
         if calendarObject is None:
             returnValue(NoDropboxHere())
@@ -1817,13 +1819,24 @@
     @inlineCallbacks
     def getChild(self, name):
         attachmentObject = yield self._newStoreCalendarObject.managedAttachmentRetrieval(name)
-        result = CalendarAttachment(
-            None,
-            attachmentObject,
-            name,
-            True,
-            principalCollections=self.principalCollections()
-        )
+        if attachmentObject is not None:
+            result = CalendarAttachment(
+                None,
+                attachmentObject,
+                name,
+                True,
+                principalCollections=self.principalCollections()
+            )
+        else:
+            attachment = yield self._newStoreCalendarObject.attachmentWithName(name)
+            result = CalendarAttachment(
+                self._newStoreCalendarObject,
+                attachment,
+                name,
+                False,
+                principalCollections=self.principalCollections()
+            )
+
         self.propagateTransaction(result)
         returnValue(result)
 
@@ -1835,6 +1848,8 @@
     @inlineCallbacks
     def listChildren(self):
         l = (yield self._newStoreCalendarObject.managedAttachmentList())
+        for attachment in (yield self._newStoreCalendarObject.attachments()):
+            l.append(attachment.name())
         returnValue(l)
 
 

Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/others/attachment_migration.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/others/attachment_migration.py	2014-02-19 20:02:12 UTC (rev 12726)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/others/attachment_migration.py	2014-02-19 21:41:20 UTC (rev 12727)
@@ -15,16 +15,17 @@
 ##
 
 from twisted.internet.defer import inlineCallbacks, returnValue
-from txdav.caldav.datastore.sql import CalendarStoreFeatures
 
-import os
-
 """
 Upgrader that checks for any dropbox attachments, and upgrades them all to managed attachments.
 
 This makes use of a MANAGED-ATTACHMENTS flag in the CALENDARSERVER table to determine whether the upgrade has been
 done for this store. If it has been done, the store will advertise that to the app layer and that must prevent the
 use of dropbox in the future.
+
+Changed: this no longer upgrades existing dropbox attachments. Instead it just turns on managed attachment support.
+The existing attachments still appear as ATTACH properties that clients can download and remove from the calendar
+data if needed. All new attachments are now managed.
 """
 
 @inlineCallbacks
@@ -39,35 +40,13 @@
         returnValue(None)
 
     statusKey = "MANAGED-ATTACHMENTS"
-    storeWrapper = CalendarStoreFeatures(upgrader.sqlStore)
     txn = upgrader.sqlStore.newTransaction("attachment_migration.doUpgrade")
     try:
         managed = (yield txn.calendarserverValue(statusKey, raiseIfMissing=False))
         if managed is None:
-            upgrader.log.warn("Checking for dropbox migration")
-            needUpgrade = (yield storeWrapper.hasDropboxAttachments(txn))
-        else:
-            needUpgrade = False
-        if needUpgrade:
-            upgrader.log.warn("Starting dropbox migration")
-            yield storeWrapper.upgradeToManagedAttachments(batchSize=10)
-            upgrader.log.warn("Finished dropbox migration")
-        else:
-            upgrader.log.warn("No dropbox migration needed")
-        if managed is None:
+            upgrader.log.warn("Managed attachments enabled")
             yield txn.setCalendarserverValue(statusKey, "1")
 
-        # Set attachment directory ownership as upgrade runs as root
-        # but child processes running as something else need to manipulate
-        # the attachment files
-        sqlAttachmentsPath = upgrader.sqlStore.attachmentsPath
-        if (sqlAttachmentsPath and sqlAttachmentsPath.exists() and
-            (upgrader.uid or upgrader.gid)):
-            uid = upgrader.uid or -1
-            gid = upgrader.gid or -1
-            for fp in sqlAttachmentsPath.walk():
-                os.chown(fp.path, uid, gid)
-
     except RuntimeError:
         yield txn.abort()
         raise

Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/others/test/test_attachment_migration.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/others/test/test_attachment_migration.py	2014-02-19 20:02:12 UTC (rev 12726)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/upgrade/sql/others/test/test_attachment_migration.py	2014-02-19 21:41:20 UTC (rev 12727)
@@ -113,7 +113,7 @@
 
         upgrader = UpgradeDatabaseOtherStep(store)
         yield attachment_migration.doUpgrade(upgrader)
-        self.assertTrue(didUpgrade[0])
+        self.assertFalse(didUpgrade[0])
 
         txn = upgrader.sqlStore.newTransaction()
         managed = (yield txn.calendarserverValue("MANAGED-ATTACHMENTS", raiseIfMissing=False))
@@ -248,7 +248,7 @@
             From=at,
         ).on(txn))[0][0]
         yield txn.commit()
-        self.assertEqual(count, 0)
+        self.assertEqual(count, 1)
         self.assertNotEqual(managed, None)
 
-        self.assertFalse(os.path.exists(fp.path))
+        self.assertTrue(os.path.exists(fp.path))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/5c89ae82/attachment.html>


More information about the calendarserver-changes mailing list