[CalendarServer-changes] [7616] CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore

source_changes at macosforge.org source_changes at macosforge.org
Mon Jun 20 11:44:02 PDT 2011


Revision: 7616
          http://trac.macosforge.org/projects/calendarserver/changeset/7616
Author:   glyph at apple.com
Date:     2011-06-20 11:44:02 -0700 (Mon, 20 Jun 2011)
Log Message:
-----------
fixes for new/replaced attachment tests; clean up after created attachments

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

Modified: CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/file.py
===================================================================
--- CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/file.py	2011-06-20 18:43:51 UTC (rev 7615)
+++ CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/file.py	2011-06-20 18:44:02 UTC (rev 7616)
@@ -594,7 +594,8 @@
         """
         self._attachment = attachment
         self._contentType = contentType
-        self._file = self._attachment._path.open("w")
+        self._path = self._attachment._path.temporarySibling()
+        self._file = self._path.open("w")
 
 
     def write(self, data):
@@ -605,13 +606,16 @@
     def loseConnection(self):
         home = self._attachment._calendarObject._calendar._home
         oldSize = self._attachment.size()
+        newSize = self._file.tell()
+        # FIXME: do anything
+        self._file.close()
 
-        if home.quotaAllowedBytes() < ((home.quotaUsedBytes())
-                                       + (self._file.tell() - oldSize)):
+        if home.quotaAllowedBytes() < (home.quotaUsedBytes()
+                                       + (newSize - oldSize)):
+            self._path.remove()
             return fail(QuotaExceeded())
 
-        # FIXME: do anything
-        self._file.close()
+        self._path.moveTo(self._attachment._path)
 
         md5 = hashlib.md5(self._attachment._path.getContent()).hexdigest()
         props = self._attachment.properties()
@@ -621,9 +625,7 @@
         props[md5key] = TwistedGETContentMD5.fromString(md5)
 
         # Adjust quota
-        home.adjustQuotaUsedBytes(
-            self._attachment.size() - oldSize
-        )
+        home.adjustQuotaUsedBytes(newSize - oldSize)
         props.flush()
         return succeed(None)
 
@@ -667,7 +669,7 @@
 
     def properties(self):
         uid = self._calendarObject._parentCollection._home.uid()
-        return PropertyStore(uid, lambda :self._path)
+        return PropertyStore(uid, lambda: self._path)
 
 
     def store(self, contentType):

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:43:51 UTC (rev 7615)
+++ CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/sql.py	2011-06-20 18:44:02 UTC (rev 7616)
@@ -772,6 +772,7 @@
 
         if home.quotaAllowedBytes() < ((yield home.quotaUsedBytes())
                                        + (len(self.buf) - oldSize)):
+            yield self.attachment._internalRemove()
             raise QuotaExceeded()
 
         self.attachment._path.setContent(self.buf)
@@ -934,8 +935,7 @@
     def remove(self):
         oldSize = self._size
         self._txn.postCommit(self._path.remove)
-        yield self._removeStatement.on(self._txn, dropboxID=self._dropboxID,
-                                       path=self._name)
+        yield self._internalRemove()
         # Adjust quota
         home = (yield self._txn.calendarHomeWithResourceID(self._ownerHomeID))
         if home:
@@ -945,6 +945,16 @@
             yield home.notifyChanged()
 
 
+    def _internalRemove(self):
+        """
+        Just delete the row; don't do any accounting / bookkeeping.  (This is
+        for attachments that have failed to be created due to errors during
+        storage.)
+        """
+        return self._removeStatement.on(self._txn, dropboxID=self._dropboxID,
+                                        path=self._name)
+
+
     # IDataStoreObject
     def contentType(self):
         return self._contentType
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110620/adfab879/attachment-0001.html>


More information about the calendarserver-changes mailing list