[CalendarServer-changes] [7610] CalendarServer/branches/users/glyph/quota/txdav/caldav
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jun 20 11:42:57 PDT 2011
Revision: 7610
http://trac.macosforge.org/projects/calendarserver/changeset/7610
Author: glyph at apple.com
Date: 2011-06-20 11:42:57 -0700 (Mon, 20 Jun 2011)
Log Message:
-----------
make sql tests pass with a few stubs and an actual quota check.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/sql.py
CalendarServer/branches/users/glyph/quota/txdav/caldav/icalendarstore.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:42:45 UTC (rev 7609)
+++ CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/sql.py 2011-06-20 18:42:57 UTC (rev 7610)
@@ -187,7 +187,15 @@
yield self.createCalendarWithName("inbox")
+ def quotaAllowedBytes(self):
+ """
+ The configured number of allowed bytes for attachments in this calendar
+ home.
+ """
+ return 1000
+
+
class Calendar(CommonHomeChild):
"""
File-based implementation of L{ICalendar}.
@@ -760,10 +768,17 @@
@inlineCallbacks
def loseConnection(self):
- old_size = self.attachment.size()
+ # FIXME: this should be synchronously accessible; IAttachment should
+ # have a method for getting its parent just as CalendarObject/Calendar
+ # do.
+ home = (
+ yield self._txn.calendarHomeWithResourceID(
+ self.attachment._ownerHomeID))
- if home.quotaAllowedBytes() - (home.quotaUsedBytes() +
- self.attachment.size()):
+ oldSize = self.attachment.size()
+
+ if home.quotaAllowedBytes() < ((yield home.quotaUsedBytes())
+ + (len(self.buf) - oldSize)):
raise QuotaExceeded()
self.attachment._path.setContent(self.buf)
@@ -784,18 +799,30 @@
Return=(att.CREATED, att.MODIFIED)).on(self._txn))[0]
)
- home = (
- yield self._txn.calendarHomeWithResourceID(
- self.attachment._ownerHomeID))
if home:
# Adjust quota
- yield home.adjustQuotaUsedBytes(self.attachment.size() - old_size)
+ yield home.adjustQuotaUsedBytes(self.attachment.size() - oldSize)
# Send change notification to home
yield home.notifyChanged()
+ def getPeer(self):
+ raise NotImplementedError()
+ return 'Storing attachment <%r>' % (self.attachment._path,)
+
+ def getHost(self):
+ raise NotImplementedError()
+ return 'Storing attachment (host) <%r>' % (self.attachment._path,)
+
+
+ def writeSequence(self, seq):
+ raise NotImplementedError()
+ return self.write(''.join(seq))
+
+
+
def sqltime(value):
return datetimeMktime(parseSQLTimestamp(value))
@@ -912,14 +939,14 @@
@inlineCallbacks
def remove(self):
- old_size = self._size
+ oldSize = self._size
self._txn.postCommit(self._path.remove)
yield self._removeStatement.on(self._txn, dropboxID=self._dropboxID,
path=self._name)
# Adjust quota
home = (yield self._txn.calendarHomeWithResourceID(self._ownerHomeID))
if home:
- yield home.adjustQuotaUsedBytes(-old_size)
+ yield home.adjustQuotaUsedBytes(-oldSize)
# Send change notification to home
yield home.notifyChanged()
Modified: CalendarServer/branches/users/glyph/quota/txdav/caldav/icalendarstore.py
===================================================================
--- CalendarServer/branches/users/glyph/quota/txdav/caldav/icalendarstore.py 2011-06-20 18:42:45 UTC (rev 7609)
+++ CalendarServer/branches/users/glyph/quota/txdav/caldav/icalendarstore.py 2011-06-20 18:42:57 UTC (rev 7610)
@@ -24,7 +24,6 @@
from txdav.idav import IDataStoreObject, IDataStore
from twisted.internet.interfaces import ITransport
-from twisted.internet.interfaces import IConsumer
from txdav.idav import INotifier
@@ -464,7 +463,7 @@
-class IAttachmentStorageTransport(ITransport, IConsumer):
+class IAttachmentStorageTransport(ITransport):
"""
An L{IAttachmentStorageTransport} is a transport which stores the bytes
written to in a calendar attachment.
@@ -476,6 +475,8 @@
have failed, and no attachment data will be stored.
"""
+ # Note: should also require IConsumer
+
def loseConnection(reason):
"""
The attachment has completed being uploaded successfully.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110620/4017bcb4/attachment.html>
More information about the calendarserver-changes
mailing list