<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12728] CalendarServer/trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12728">12728</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-02-19 13:45:57 -0800 (Wed, 19 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwistedcaldavstorebridgepy">CalendarServer/trunk/twistedcaldav/storebridge.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoreupgradesqlothersattachment_migrationpy">CalendarServer/trunk/txdav/common/datastore/upgrade/sql/others/attachment_migration.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoreupgradesqlotherstesttest_attachment_migrationpy">CalendarServer/trunk/txdav/common/datastore/upgrade/sql/others/test/test_attachment_migration.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktwistedcaldavstorebridgepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/storebridge.py (12727 => 12728)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/storebridge.py        2014-02-19 21:41:20 UTC (rev 12727)
+++ CalendarServer/trunk/twistedcaldav/storebridge.py        2014-02-19 21:45:57 UTC (rev 12728)
</span><span class="lines">@@ -1737,7 +1737,9 @@
</span><span class="cx">         if calendarObject:
</span><span class="cx">             l = (yield calendarObject.managedAttachmentList())
</span><span class="cx">             if len(l) == 0:
</span><del>-                calendarObject = None
</del><ins>+                l = (yield calendarObject.attachments())
+                if len(l) == 0:
+                    calendarObject = None
</ins><span class="cx"> 
</span><span class="cx">         if calendarObject is None:
</span><span class="cx">             returnValue(NoDropboxHere())
</span><span class="lines">@@ -1840,13 +1842,24 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def getChild(self, name):
</span><span class="cx">         attachmentObject = yield self._newStoreCalendarObject.managedAttachmentRetrieval(name)
</span><del>-        result = CalendarAttachment(
-            None,
-            attachmentObject,
-            name,
-            True,
-            principalCollections=self.principalCollections()
-        )
</del><ins>+        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()
+            )
+
</ins><span class="cx">         self.propagateTransaction(result)
</span><span class="cx">         returnValue(result)
</span><span class="cx"> 
</span><span class="lines">@@ -1858,6 +1871,8 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def listChildren(self):
</span><span class="cx">         l = (yield self._newStoreCalendarObject.managedAttachmentList())
</span><ins>+        for attachment in (yield self._newStoreCalendarObject.attachments()):
+            l.append(attachment.name())
</ins><span class="cx">         returnValue(l)
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoreupgradesqlothersattachment_migrationpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/others/attachment_migration.py (12727 => 12728)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/others/attachment_migration.py        2014-02-19 21:41:20 UTC (rev 12727)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/others/attachment_migration.py        2014-02-19 21:45:57 UTC (rev 12728)
</span><span class="lines">@@ -15,16 +15,17 @@
</span><span class="cx"> ##
</span><span class="cx"> 
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><del>-from txdav.caldav.datastore.sql import CalendarStoreFeatures
</del><span class="cx"> 
</span><del>-import os
-
</del><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> Upgrader that checks for any dropbox attachments, and upgrades them all to managed attachments.
</span><span class="cx"> 
</span><span class="cx"> This makes use of a MANAGED-ATTACHMENTS flag in the CALENDARSERVER table to determine whether the upgrade has been
</span><span class="cx"> done for this store. If it has been done, the store will advertise that to the app layer and that must prevent the
</span><span class="cx"> use of dropbox in the future.
</span><ins>+
+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.
</ins><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx"> @inlineCallbacks
</span><span class="lines">@@ -39,35 +40,13 @@
</span><span class="cx">         returnValue(None)
</span><span class="cx"> 
</span><span class="cx">     statusKey = &quot;MANAGED-ATTACHMENTS&quot;
</span><del>-    storeWrapper = CalendarStoreFeatures(upgrader.sqlStore)
</del><span class="cx">     txn = upgrader.sqlStore.newTransaction(&quot;attachment_migration.doUpgrade&quot;)
</span><span class="cx">     try:
</span><span class="cx">         managed = (yield txn.calendarserverValue(statusKey, raiseIfMissing=False))
</span><span class="cx">         if managed is None:
</span><del>-            upgrader.log.warn(&quot;Checking for dropbox migration&quot;)
-            needUpgrade = (yield storeWrapper.hasDropboxAttachments(txn))
-        else:
-            needUpgrade = False
-        if needUpgrade:
-            upgrader.log.warn(&quot;Starting dropbox migration&quot;)
-            yield storeWrapper.upgradeToManagedAttachments(batchSize=10)
-            upgrader.log.warn(&quot;Finished dropbox migration&quot;)
-        else:
-            upgrader.log.warn(&quot;No dropbox migration needed&quot;)
-        if managed is None:
</del><ins>+            upgrader.log.warn(&quot;Managed attachments enabled&quot;)
</ins><span class="cx">             yield txn.setCalendarserverValue(statusKey, &quot;1&quot;)
</span><span class="cx"> 
</span><del>-        # 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)
-
</del><span class="cx">     except RuntimeError:
</span><span class="cx">         yield txn.abort()
</span><span class="cx">         raise
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoreupgradesqlotherstesttest_attachment_migrationpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/others/test/test_attachment_migration.py (12727 => 12728)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/others/test/test_attachment_migration.py        2014-02-19 21:41:20 UTC (rev 12727)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/others/test/test_attachment_migration.py        2014-02-19 21:45:57 UTC (rev 12728)
</span><span class="lines">@@ -113,7 +113,7 @@
</span><span class="cx"> 
</span><span class="cx">         upgrader = UpgradeDatabaseOtherStep(store)
</span><span class="cx">         yield attachment_migration.doUpgrade(upgrader)
</span><del>-        self.assertTrue(didUpgrade[0])
</del><ins>+        self.assertFalse(didUpgrade[0])
</ins><span class="cx"> 
</span><span class="cx">         txn = upgrader.sqlStore.newTransaction()
</span><span class="cx">         managed = (yield txn.calendarserverValue(&quot;MANAGED-ATTACHMENTS&quot;, raiseIfMissing=False))
</span><span class="lines">@@ -248,7 +248,7 @@
</span><span class="cx">             From=at,
</span><span class="cx">         ).on(txn))[0][0]
</span><span class="cx">         yield txn.commit()
</span><del>-        self.assertEqual(count, 0)
</del><ins>+        self.assertEqual(count, 1)
</ins><span class="cx">         self.assertNotEqual(managed, None)
</span><span class="cx"> 
</span><del>-        self.assertFalse(os.path.exists(fp.path))
</del><ins>+        self.assertTrue(os.path.exists(fp.path))
</ins></span></pre>
</div>
</div>

</body>
</html>