[CalendarServer-changes] [7621] CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/sql .py

source_changes at macosforge.org source_changes at macosforge.org
Mon Jun 20 11:45:01 PDT 2011


Revision: 7621
          http://trac.macosforge.org/projects/calendarserver/changeset/7621
Author:   glyph at apple.com
Date:     2011-06-20 11:45:01 -0700 (Mon, 20 Jun 2011)
Log Message:
-----------
Remember whether the attachment was just created or not, so as to issue or not issue SQL statements to delete the attachment as appropriate when quota is exceeded.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/sql.py

Modified: CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/sql.py	2011-06-20 18:44:47 UTC (rev 7620)
+++ CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/sql.py	2011-06-20 18:45:01 UTC (rev 7621)
@@ -687,7 +687,7 @@
         yield attachment.remove()
 
     def attachmentWithName(self, name):
-        return Attachment.attachmentWithName(self._txn, self._dropboxID, name)
+        return Attachment.loadWithName(self._txn, self._dropboxID, name)
 
     def attendeesCanManageAttachments(self):
         return self._attachment == _ATTACHMENTS_MODE_WRITE
@@ -741,11 +741,12 @@
 
     implements(IAttachmentStorageTransport)
 
-    def __init__(self, attachment, contentType):
+    def __init__(self, attachment, contentType, creating=False):
         self.attachment = attachment
         self.contentType = contentType
         self.buf = ''
         self.hash = hashlib.md5()
+        self.creating = creating
 
 
     @property
@@ -764,6 +765,11 @@
         # FIXME: this should be synchronously accessible; IAttachment should
         # have a method for getting its parent just as CalendarObject/Calendar
         # do.
+
+        # FIXME: If this method isn't called, the transaction should be
+        # prevented from committing successfully.  It's not valid to have an
+        # attachment that doesn't point to a real file.
+
         home = (
             yield self._txn.calendarHomeWithResourceID(
                 self.attachment._ownerHomeID))
@@ -772,7 +778,8 @@
 
         if home.quotaAllowedBytes() < ((yield home.quotaUsedBytes())
                                        + (len(self.buf) - oldSize)):
-            yield self.attachment._internalRemove()
+            if self.creating:
+                yield self.attachment._internalRemove()
             raise QuotaExceeded()
 
         self.attachment._path.setContent(self.buf)
@@ -824,12 +831,13 @@
 
     implements(IAttachment)
 
-    def __init__(self, txn, dropboxID, name, ownerHomeID=None):
+    def __init__(self, txn, dropboxID, name, ownerHomeID=None, justCreated=False):
         self._txn = txn
         self._dropboxID = dropboxID
         self._name = name
         self._ownerHomeID = ownerHomeID
         self._size = 0
+        self._justCreated = justCreated
 
 
     @classmethod
@@ -853,7 +861,7 @@
             pass
 
         # Now create the DB entry
-        attachment = cls(txn, dropboxID, name, ownerHomeID)
+        attachment = cls(txn, dropboxID, name, ownerHomeID, True)
         att = schema.ATTACHMENT
         yield Insert({
             att.CALENDAR_HOME_RESOURCE_ID : ownerHomeID,
@@ -868,8 +876,8 @@
 
     @classmethod
     @inlineCallbacks
-    def attachmentWithName(cls, txn, dropboxID, name):
-        attachment = Attachment(txn, dropboxID, name)
+    def loadWithName(cls, txn, dropboxID, name):
+        attachment = cls(txn, dropboxID, name)
         attachment = (yield attachment.initFromStore())
         returnValue(attachment)
 
@@ -916,7 +924,7 @@
 
 
     def store(self, contentType):
-        return AttachmentStorageTransport(self, contentType)
+        return AttachmentStorageTransport(self, contentType, self._justCreated)
 
 
     def retrieve(self, protocol):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110620/ec130044/attachment.html>


More information about the calendarserver-changes mailing list