[CalendarServer-changes] [14667] CalendarServer/trunk/txdav
source_changes at macosforge.org
source_changes at macosforge.org
Wed Apr 8 17:32:49 PDT 2015
Revision: 14667
http://trac.calendarserver.org//changeset/14667
Author: sagen at apple.com
Date: 2015-04-08 17:32:49 -0700 (Wed, 08 Apr 2015)
Log Message:
-----------
When an event moves to the trash, the attachments are not removed. Once an event is fully removed, its attachments are then removed
Modified Paths:
--------------
CalendarServer/trunk/txdav/caldav/datastore/sql.py
CalendarServer/trunk/txdav/caldav/datastore/test/test_attachments.py
CalendarServer/trunk/txdav/common/datastore/sql.py
CalendarServer/trunk/txdav/common/datastore/test/util.py
Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py 2015-04-08 13:52:06 UTC (rev 14666)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py 2015-04-09 00:32:49 UTC (rev 14667)
@@ -4152,11 +4152,6 @@
if do_implicit_action:
yield NamedLock.acquire(self._txn, "ImplicitUIDLock:{0}".format(hashlib.md5(calendar.resourceUID()).hexdigest(),))
- # Need to also remove attachments
- if internal_state != ComponentRemoveState.INTERNAL:
- if self._dropboxID:
- yield DropBoxAttachment.resourceRemoved(self._txn, self._resourceID, self._dropboxID)
- yield ManagedAttachment.resourceRemoved(self._txn, self._resourceID)
if isinbox:
bypassTrash = True
@@ -4169,6 +4164,12 @@
bypassTrash = True
if bypassTrash:
+ # Need to also remove attachments
+ if internal_state != ComponentRemoveState.INTERNAL:
+ if self._dropboxID:
+ yield DropBoxAttachment.resourceRemoved(self._txn, self._resourceID, self._dropboxID)
+ yield ManagedAttachment.resourceRemoved(self._txn, self._resourceID)
+
yield super(CalendarObject, self).reallyRemove()
else:
# Always remove the group attendee link to prevent trashed items from being reconciled when a group changes
Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_attachments.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/test_attachments.py 2015-04-08 13:52:06 UTC (rev 14666)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_attachments.py 2015-04-09 00:32:49 UTC (rev 14667)
@@ -650,6 +650,8 @@
L{ICalendarObject.remove} will remove an associated calendar
attachment.
"""
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
# Create attachment
obj = yield self.calendarObjectUnderTest()
@@ -670,11 +672,25 @@
yield self.commit()
self.assertNotEqual(quota, 0)
- # Remove resource
+ # Remove resource (to trash)
obj = yield self.calendarObjectUnderTest()
yield obj.remove()
yield self.commit()
+ # Attachments still exist and count towards quota
+ self.assertTrue(os.path.exists(apath))
+
+ home = (yield self.transactionUnderTest().calendarHomeWithUID(u"home1"))
+ quota = (yield home.quotaUsedBytes())
+ yield self.commit()
+ self.assertNotEqual(quota, 0)
+
+ # Fully remove resource
+ objects = yield self.trashObjectsUnderTest()
+ yield objects[0].remove(bypassTrash=True)
+ yield self.commit()
+
+ # Attachments don't exist and will not count towards quota
self.assertFalse(os.path.exists(apath))
home = (yield self.transactionUnderTest().calendarHomeWithUID(u"home1"))
@@ -689,6 +705,8 @@
L{ICalendarObject.remove} will remove all associated calendar
attachments.
"""
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
# Create attachment
obj = yield self.calendarObjectUnderTest()
@@ -723,7 +741,7 @@
# Remove resource
obj = yield self.calendarObjectUnderTest()
- yield obj.remove()
+ yield obj.remove(bypassTrash=True)
yield self.commit()
self.assertFalse(os.path.exists(apath1))
@@ -1261,6 +1279,8 @@
L{ICalendarObject.remove} will remove an associated calendar
attachment.
"""
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
# Create attachment
obj = yield self.calendarObjectUnderTest()
@@ -1279,11 +1299,25 @@
yield self.commit()
self.assertNotEqual(quota, 0)
- # Remove resource
+ # Remove resource (to trash)
obj = yield self.calendarObjectUnderTest()
yield obj.remove()
yield self.commit()
+ # Attachments still exist and count towards quota
+ self.assertTrue(os.path.exists(apath))
+
+ home = (yield self.transactionUnderTest().calendarHomeWithUID(u"home1"))
+ quota = (yield home.quotaUsedBytes())
+ yield self.commit()
+ self.assertNotEqual(quota, 0)
+
+ # Fully remove resource
+ objects = yield self.trashObjectsUnderTest()
+ yield objects[0].remove(bypassTrash=True)
+ yield self.commit()
+
+ # Attachments don't exist and will not count towards quota
self.assertFalse(os.path.exists(apath))
home = (yield self.transactionUnderTest().calendarHomeWithUID(u"home1"))
@@ -1328,7 +1362,7 @@
# Remove resource
obj = yield self.calendarObjectUnderTest()
- yield obj.remove()
+ yield obj.remove(bypassTrash=True)
yield self.commit()
self.assertFalse(os.path.exists(apath1))
@@ -1368,7 +1402,7 @@
# Remove resource
obj = yield self.calendarObjectUnderTest()
- yield obj.remove()
+ yield obj.remove(bypassTrash=True)
yield self.commit()
self.assertTrue(os.path.exists(apath))
@@ -1380,7 +1414,7 @@
# Remove resource
obj = yield self.calendarObjectUnderTest(name="test.ics")
- yield obj.remove()
+ yield obj.remove(bypassTrash=True)
yield self.commit()
self.assertFalse(os.path.exists(apath))
Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py 2015-04-08 13:52:06 UTC (rev 14666)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py 2015-04-09 00:32:49 UTC (rev 14667)
@@ -2934,7 +2934,9 @@
trash = yield self.getTrash()
if trash is None:
if verbose:
- print("No trash collection for principal")
+ msg = "No trash collection for principal"
+ print(msg)
+ log.info(msg)
returnValue(None)
endTime = datetime.datetime.utcnow() - datetime.timedelta(days=days)
@@ -2949,12 +2951,16 @@
continue
if verbose:
- print("Collection \"{}\":".format(displayName.encode("utf-8")))
+ msg = "Collection \"{}\":".format(displayName.encode("utf-8"))
+ print(msg)
+ log.info(msg)
for child in children:
- component = yield child.component()
- summary = component.mainComponent().propertyValue("SUMMARY", "<no title>")
if verbose:
- print(" Removing \"{}\"...".format(summary))
+ component = yield child.component()
+ summary = component.mainComponent().propertyValue("SUMMARY", "<no title>")
+ msg = " Removing \"{}\"...".format(summary)
+ print(msg)
+ log.info(msg)
yield child.reallyRemove()
if verbose:
print("")
@@ -2966,19 +2972,25 @@
collection._resourceID, end=endTime
)
if verbose:
- print("Collection \"{}\":".format(displayName.encode("utf-8")))
+ msg = "Collection \"{}\":".format(displayName.encode("utf-8"))
+ print(msg)
+ log.info(msg)
for child in children:
- component = yield child.component()
- summary = component.mainComponent().propertyValue("SUMMARY", "<no title>")
if verbose:
- print(" Removing \"{}\"...".format(summary))
+ component = yield child.component()
+ summary = component.mainComponent().propertyValue("SUMMARY", "<no title>")
+ msg = " Removing \"{}\"...".format(summary)
+ print(msg)
+ log.info(msg)
yield child.reallyRemove()
if verbose:
print("")
if collection.whenTrashed() < endTime:
if verbose:
- print("Removing collection \"{}\"...".format(displayName.encode("utf-8")))
+ msg = "Removing collection \"{}\"...".format(displayName.encode("utf-8"))
+ print(msg)
+ log.info(msg)
yield collection.reallyRemove()
Modified: CalendarServer/trunk/txdav/common/datastore/test/util.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/util.py 2015-04-08 13:52:06 UTC (rev 14666)
+++ CalendarServer/trunk/txdav/common/datastore/test/util.py 2015-04-09 00:32:49 UTC (rev 14667)
@@ -995,6 +995,20 @@
returnValue(object)
+ @inlineCallbacks
+ def trashObjectsUnderTest(
+ self, txn=None, home="home1", status=None
+ ):
+ """
+ Get the calendar detailed by
+ C{requirements[home][calendar_name][name]}.
+ """
+ home = yield self.homeUnderTest(name=home)
+ trash = yield home.getTrash()
+ objects = yield trash.objectResources()
+ returnValue(objects)
+
+
def addressbookHomeUnderTest(self, txn=None, name="home1"):
"""
Get the addressbook home detailed by C{requirements['home1']}.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150408/cc858610/attachment-0001.html>
More information about the calendarserver-changes
mailing list