[CalendarServer-changes] [5886] CalendarServer/branches/new-store

source_changes at macosforge.org source_changes at macosforge.org
Tue Jul 13 20:13:22 PDT 2010


Revision: 5886
          http://trac.macosforge.org/projects/calendarserver/changeset/5886
Author:   cdaboo at apple.com
Date:     2010-07-13 20:13:18 -0700 (Tue, 13 Jul 2010)
Log Message:
-----------
Eliminate all use of DAVFile.fp in the method module. Fix a directory render issue on non-existent
resources.

Modified Paths:
--------------
    CalendarServer/branches/new-store/twistedcaldav/extensions.py
    CalendarServer/branches/new-store/twistedcaldav/method/acl.py
    CalendarServer/branches/new-store/twistedcaldav/method/copymove.py
    CalendarServer/branches/new-store/twistedcaldav/method/copymove_contact.py
    CalendarServer/branches/new-store/twistedcaldav/method/delete.py
    CalendarServer/branches/new-store/twistedcaldav/method/mkcalendar.py
    CalendarServer/branches/new-store/twistedcaldav/method/mkcol.py
    CalendarServer/branches/new-store/twistedcaldav/method/post.py
    CalendarServer/branches/new-store/twistedcaldav/method/propfind.py
    CalendarServer/branches/new-store/twistedcaldav/method/put.py
    CalendarServer/branches/new-store/twistedcaldav/method/put_addressbook_common.py
    CalendarServer/branches/new-store/twistedcaldav/method/put_common.py
    CalendarServer/branches/new-store/twistedcaldav/method/report.py
    CalendarServer/branches/new-store/twistedcaldav/storebridge.py
    CalendarServer/branches/new-store/txdav/common/datastore/file.py

Modified: CalendarServer/branches/new-store/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/extensions.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/twistedcaldav/extensions.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -687,6 +687,9 @@
     http_REPORT = http_REPORT
 
     def render(self, request):
+        if not self.exists():
+            return responsecode.NOT_FOUND
+
         if self.isCollection():
             return self.renderDirectory(request)
         return super(DAVResource, self).render(request)

Modified: CalendarServer/branches/new-store/twistedcaldav/method/acl.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/method/acl.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/twistedcaldav/method/acl.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -41,7 +41,7 @@
     # homes cannot have ACL's set, and calendar/address object resources too.
     #
 
-    if self.fp.exists():
+    if self.exists():
         if isinstance(self, CalendarHomeFile) or isinstance(self, AddressBookHomeFile):
             raise HTTPError(responsecode.NOT_ALLOWED)
 

Modified: CalendarServer/branches/new-store/twistedcaldav/method/copymove.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/method/copymove.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/twistedcaldav/method/copymove.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -84,8 +84,8 @@
     # Check for existing destination resource
     overwrite = request.headers.getHeader("overwrite", True)
     if destination.exists() and not overwrite:
-        log.err("Attempt to copy onto existing file without overwrite flag enabled: %s"
-                % (destination.fp.path,))
+        log.err("Attempt to copy onto existing resource without overwrite flag enabled: %s"
+                % (destination,))
         raise HTTPError(StatusResponse(
             responsecode.PRECONDITION_FAILED,
             "Destination %s already exists." % (destination_uri,))
@@ -163,8 +163,8 @@
     # Check for existing destination resource
     overwrite = request.headers.getHeader("overwrite", True)
     if destination.exists() and not overwrite:
-        log.err("Attempt to copy onto existing file without overwrite flag enabled: %s"
-                % (destination.fp.path,))
+        log.err("Attempt to copy onto existing resource without overwrite flag enabled: %s"
+                % (destination,))
         raise HTTPError(StatusResponse(
             responsecode.PRECONDITION_FAILED,
             "Destination %s already exists." % (destination_uri,)
@@ -228,8 +228,8 @@
     destinationcal = False
     
     # Check the source path first
-    if not self.fp.exists():
-        log.err("File not found: %s" % (self.fp.path,))
+    if not self.exists():
+        log.err("Resource not found: %s" % (self,))
         raise HTTPError(StatusResponse(
             responsecode.NOT_FOUND,
             "Source resource %s not found." % (request.uri,)

Modified: CalendarServer/branches/new-store/twistedcaldav/method/copymove_contact.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/method/copymove_contact.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/twistedcaldav/method/copymove_contact.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -71,8 +71,8 @@
     # Check for existing destination resource
     overwrite = request.headers.getHeader("overwrite", True)
     if destination.exists() and not overwrite:
-        log.err("Attempt to copy onto existing file without overwrite flag enabled: %s"
-                % (destination.fp.path,))
+        log.err("Attempt to copy onto existing resource without overwrite flag enabled: %s"
+                % (destination,))
         raise HTTPError(StatusResponse(
             responsecode.PRECONDITION_FAILED,
             "Destination %s already exists." % (destination_uri,))
@@ -141,8 +141,8 @@
     # Check for existing destination resource
     overwrite = request.headers.getHeader("overwrite", True)
     if destination.exists() and not overwrite:
-        log.err("Attempt to copy onto existing file without overwrite flag enabled: %s"
-                % (destination.fp.path,))
+        log.err("Attempt to copy onto existing resource without overwrite flag enabled: %s"
+                % (destination,))
         raise HTTPError(StatusResponse(
             responsecode.PRECONDITION_FAILED,
             "Destination %s already exists." % (destination_uri,)
@@ -206,8 +206,8 @@
     destinationadbk = False
     
     # Check the source path first
-    if not self.fp.exists():
-        log.err("File not found: %s" % (self.fp.path,))
+    if not self.exists():
+        log.err("Resource not found: %s" % (self,))
         raise HTTPError(StatusResponse(
             responsecode.NOT_FOUND,
             "Source resource %s not found." % (request.uri,)

Modified: CalendarServer/branches/new-store/twistedcaldav/method/delete.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/method/delete.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/twistedcaldav/method/delete.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -39,8 +39,8 @@
     # index file has the entry for the deleted calendar component removed.
     #
 
-    if not self.fp.exists():
-        log.err("File not found: %s" % (self.fp.path,))
+    if not self.exists():
+        log.err("Resource not found: %s" % (self,))
         raise HTTPError(responsecode.NOT_FOUND)
 
     depth = request.headers.getHeader("depth", "infinity")

Modified: CalendarServer/branches/new-store/twistedcaldav/method/mkcalendar.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/method/mkcalendar.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/twistedcaldav/method/mkcalendar.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -50,8 +50,7 @@
     yield parent.authorize(request, (davxml.Bind(),))
 
     if self.exists():
-        log.err("Attempt to create collection where file exists: %s"
-                % (self.fp.path,))
+        log.err("Attempt to create collection where resource exists: %s"  % (self,))
         raise HTTPError(ErrorResponse(
             responsecode.FORBIDDEN,
             (davxml.dav_namespace, "resource-must-be-null"))
@@ -59,7 +58,7 @@
 
     if not parent.isCollection():
         log.err("Attempt to create collection with non-collection parent: %s"
-                % (self.fp.path,))
+                % (self,))
         raise HTTPError(ErrorResponse(
             responsecode.CONFLICT,
             (caldavxml.caldav_namespace, "calendar-collection-location-ok"))
@@ -78,9 +77,6 @@
     if doc is not None:
         makecalendar = doc.root_element
         if not isinstance(makecalendar, caldavxml.MakeCalendar):
-            # Clean up
-            if self.fp.exists(): self.fp.remove()
-
             error = ("Non-%s element in MKCALENDAR request body: %s"
                      % (caldavxml.MakeCalendar.name, makecalendar))
             log.err(error)

Modified: CalendarServer/branches/new-store/twistedcaldav/method/mkcol.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/method/mkcol.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/twistedcaldav/method/mkcol.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -53,8 +53,8 @@
     yield parent.authorize(request, (davxml.Bind(),))
 
     if self.exists():
-        log.err("Attempt to create collection where file exists: %s"
-                % (self.fp.path,))
+        log.err("Attempt to create collection where resource exists: %s"
+                % (self,))
         raise HTTPError(ErrorResponse(
             responsecode.FORBIDDEN,
             (davxml.dav_namespace, "resource-must-be-null"))
@@ -62,7 +62,7 @@
 
     if not parent.isCollection():
         log.err("Attempt to create collection with non-collection parent: %s"
-                % (self.fp.path,))
+                % (self,))
         raise HTTPError(ErrorResponse(
             responsecode.CONFLICT,
             (davxml.dav_namespace, "collection-location-ok"))
@@ -111,9 +111,6 @@
         # Parse response body
         mkcol = doc.root_element
         if not isinstance(mkcol, mkcolxml.MakeCollection):
-            # Clean up
-            if self.fp.exists(): self.fp.remove()
-
             error = ("Non-%s element in MKCOL request body: %s"
                      % (mkcolxml.MakeCollection.name, mkcol))
             log.err(error)

Modified: CalendarServer/branches/new-store/twistedcaldav/method/post.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/method/post.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/twistedcaldav/method/post.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -90,7 +90,7 @@
                 raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-data"), description="No calendar data"))
 
             # Create a new name if one was not provided
-            name =  md5(str(calendardata) + str(time.time()) + self.fp.path).hexdigest() + ".ics"
+            name =  md5(str(calendardata) + str(time.time()) + request.path).hexdigest() + ".ics"
         
             # Get a resource for the new item
             newchildURL = joinURL(parentURL, name)
@@ -139,7 +139,7 @@
                 raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (carddav_namespace, "valid-address-data"), description="No address data"))
 
             # Create a new name if one was not provided
-            name =  md5(str(vcarddata) + str(time.time()) + self.fp.path).hexdigest() + ".vcf"
+            name =  md5(str(vcarddata) + str(time.time()) + request.path).hexdigest() + ".vcf"
         
             # Get a resource for the new item
             newchildURL = joinURL(parentURL, name)

Modified: CalendarServer/branches/new-store/twistedcaldav/method/propfind.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/method/propfind.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/twistedcaldav/method/propfind.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -51,7 +51,7 @@
     Respond to a PROPFIND request. (RFC 2518, section 8.1)
     """
     if not self.exists():
-        log.err("File not found: %s" % (self.fp.path,))
+        log.err("Resource not found: %s" % (self,))
         raise HTTPError(responsecode.NOT_FOUND)
 
     #

Modified: CalendarServer/branches/new-store/twistedcaldav/method/put.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/method/put.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/twistedcaldav/method/put.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -82,7 +82,6 @@
             raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
 
     elif isAddressBookCollectionResource(parent):
-        self.fp.restat(False)
 
         # Content-type check
         content_type = request.headers.getHeader("content-type")
@@ -125,7 +124,7 @@
             request.extendedLogItems = {}
         clength = request.headers.getHeader("content-length", 0)
         if clength == 0:
-            clength = self.fp.getsize()
+            clength = self.contentLength()
         request.extendedLogItems["cl"] = str(clength)
         
         returnValue(result)

Modified: CalendarServer/branches/new-store/twistedcaldav/method/put_addressbook_common.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/method/put_addressbook_common.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/twistedcaldav/method/put_addressbook_common.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -189,9 +189,9 @@
             else:
                 # Get UID from original resource
                 self.source_index = self.sourceparent.index()
-                self.uid = self.source_index.resourceUIDForName(self.source.fp.basename())
+                self.uid = self.source_index.resourceUIDForName(self.source.name())
                 if self.uid is None:
-                    log.err("Source vcard does not have a UID: %s" % self.source.fp.basename())
+                    log.err("Source vcard does not have a UID: %s" % self.source.name())
                     raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (carddav_namespace, "valid-addressbook-object-resource")))
 
                 # FIXME: We need this here because we have to re-index the destination. Ideally it
@@ -213,7 +213,7 @@
         """
         result = True
         message = ""
-        filename = self.destination.fp.basename()
+        filename = self.destination.name()
         if filename.startswith("."):
             result = False
             message = "File name %s not allowed in vcard collection" % (filename,)
@@ -285,12 +285,12 @@
 
         # Adjust for a move into same vcard collection
         oldname = None
-        if self.sourceparent and (self.sourceparent.fp.path == self.destinationparent.fp.path) and self.deletesource:
-            oldname = self.source.fp.basename()
+        if self.sourceparent and (self.sourceparent == self.destinationparent) and self.deletesource:
+            oldname = self.source.name()
 
         # UID must be unique
         index = self.destinationparent.index()
-        if not index.isAllowedUID(uid, oldname, self.destination.fp.basename()):
+        if not index.isAllowedUID(uid, oldname, self.destination.name()):
             rname = index.resourceNameForUID(uid)
             # This can happen if two simultaneous PUTs occur with the same UID.
             # i.e. one PUT has reserved the UID but has not yet written the resource,
@@ -302,10 +302,10 @@
             message = "Address book resource %s already exists with same UID %s" % (rname, uid)
         else:
             # Cannot overwrite a resource with different UID
-            if self.destination.fp.exists():
-                olduid = index.resourceUIDForName(self.destination.fp.basename())
+            if self.destination.exists():
+                olduid = index.resourceUIDForName(self.destination.name())
                 if olduid != uid:
-                    rname = self.destination.fp.basename()
+                    rname = self.destination.name()
                     result = False
                     message = "Cannot overwrite vcard resource %s with different UID %s" % (rname, olduid)
         
@@ -382,7 +382,7 @@
     def doSourceDelete(self):
         # Delete the source resource
         yield self.source.storeRemove(self.request, self.source_uri)
-        log.debug("Source removed %s" % (self.source.fp.path,))
+        log.debug("Source removed %s" % (self.source,))
         returnValue(None)
 
     @inlineCallbacks

Modified: CalendarServer/branches/new-store/twistedcaldav/method/put_common.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/method/put_common.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/twistedcaldav/method/put_common.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -280,9 +280,9 @@
             else:
                 # Get UID from original resource
                 self.source_index = self.sourceparent.index()
-                self.uid = self.source_index.resourceUIDForName(self.source.fp.basename())
+                self.uid = self.source_index.resourceUIDForName(self.source.name())
                 if self.uid is None:
-                    log.err("Source calendar does not have a UID: %s" % self.source.fp.basename())
+                    log.err("Source calendar does not have a UID: %s" % self.source)
                     raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-object-resource")))
 
                 # FIXME: We need this here because we have to re-index the destination. Ideally it
@@ -359,7 +359,7 @@
         """
         result = True
         message = ""
-        filename = self.destination.fp.basename()
+        filename = self.destination.name()
         if filename.startswith("."):
             result = False
             message = "File name %s not allowed in calendar collection" % (filename,)
@@ -589,12 +589,12 @@
         
         # Adjust for a move into same calendar collection 
         oldname = None 
-        if self.sourceparent and (self.sourceparent.fp.path == self.destinationparent.fp.path) and self.deletesource: 
-            oldname = self.source.fp.basename() 
+        if self.sourceparent and (self.sourceparent == self.destinationparent) and self.deletesource: 
+            oldname = self.source.name() 
         
         # UID must be unique 
         index = self.destinationparent.index() 
-        if not index.isAllowedUID(uid, oldname, self.destination.fp.basename()): 
+        if not index.isAllowedUID(uid, oldname, self.destination.name()): 
             rname = index.resourceNameForUID(uid) 
             # This can happen if two simultaneous PUTs occur with the same UID. 
             # i.e. one PUT has reserved the UID but has not yet written the resource, 
@@ -605,10 +605,10 @@
             message = "Calendar resource %s already exists with same UID %s" % (rname, uid) 
         else: 
             # Cannot overwrite a resource with different UID 
-            if self.destination.fp.exists(): 
-                olduid = index.resourceUIDForName(self.destination.fp.basename()) 
+            if self.destination.exists(): 
+                olduid = index.resourceUIDForName(self.destination.name()) 
                 if olduid != uid: 
-                    rname = self.destination.fp.basename() 
+                    rname = self.destination.name() 
                     result = False 
                     message = "Cannot overwrite calendar resource %s with different UID %s" % (rname, olduid) 
          
@@ -777,7 +777,7 @@
     def doSourceDelete(self):
         # Delete the source resource
         yield self.source.storeRemove(self.request, False, self.source_uri)
-        log.debug("Source removed %s" % (self.source.fp.path,))
+        log.debug("Source removed %s" % (self.source,))
         returnValue(None)
 
     @inlineCallbacks

Modified: CalendarServer/branches/new-store/twistedcaldav/method/report.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/method/report.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/twistedcaldav/method/report.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -47,8 +47,8 @@
     """
     Respond to a REPORT request. (RFC 3253, section 3.6)
     """
-    if not self.fp.exists():
-        log.err("File not found: %s" % (self.fp.path,))
+    if not self.exists():
+        log.err("Resource not found: %s" % (self,))
         raise HTTPError(responsecode.NOT_FOUND)
 
     #

Modified: CalendarServer/branches/new-store/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/branches/new-store/twistedcaldav/storebridge.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/twistedcaldav/storebridge.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -26,6 +26,7 @@
 
 from twisted.internet.defer import succeed, inlineCallbacks, returnValue
 from twisted.internet.protocol import Protocol
+from twisted.python.util import FancyEqMixin
 
 from twext.python import vcomponent
 from twext.python.filepath import CachingFilePath as FilePath
@@ -790,11 +791,13 @@
 
 
 
-class CalendarObjectFile(CalDAVFile):
+class CalendarObjectFile(CalDAVFile, FancyEqMixin):
     """
     A resource wrapping a calendar object.
     """
 
+    compareAttributes = '_newStoreObject'.split()
+
     def __init__(self, calendarObject, *args, **kw):
         """
         Construct a L{CalendarObjectFile} from an L{ICalendarObject}.
@@ -840,6 +843,8 @@
         # FIXME: Tests
         return True
 
+    def name(self):
+        return self._newStoreObject.name()
 
     def etag(self):
         # FIXME: far too slow to be used for real, but I needed something to
@@ -1039,8 +1044,10 @@
 
 
 
-class ProtoCalendarObjectFile(CalDAVFile):
+class ProtoCalendarObjectFile(CalDAVFile, FancyEqMixin):
 
+    compareAttributes = '_newStoreParentCalendar'.split()
+
     def __init__(self, parentCalendar, *a, **kw):
         super(ProtoCalendarObjectFile, self).__init__(*a, **kw)
         self._newStoreParentCalendar = parentCalendar
@@ -1067,6 +1074,9 @@
         return False
 
 
+    def name(self):
+        return self.fp.basename()
+
     def quotaSize(self, request):
         # FIXME: tests, workingness
         return succeed(0)
@@ -1484,11 +1494,13 @@
 
 
 
-class AddressBookObjectFile(CalDAVFile):
+class AddressBookObjectFile(CalDAVFile, FancyEqMixin):
     """
     A resource wrapping a addressbook object.
     """
 
+    compareAttributes = '_newStoreObject'.split()
+
     def __init__(self, Object, *args, **kw):
         """
         Construct a L{AddressBookObjectFile} from an L{IAddressBookObject}.
@@ -1533,6 +1545,9 @@
         return True
 
 
+    def name(self):
+        return self._newStoreObject.name()
+
     def etag(self):
         # FIXME: far too slow to be used for real, but I needed something to
         # placate the etag computation in the case where the file doesn't exist
@@ -1646,8 +1661,10 @@
 
 
 
-class ProtoAddressBookObjectFile(CalDAVFile):
+class ProtoAddressBookObjectFile(CalDAVFile, FancyEqMixin):
 
+    compareAttributes = '_newStoreParentAddressBook'.split()
+
     def __init__(self, parentAddressBook, *a, **kw):
         super(ProtoAddressBookObjectFile, self).__init__(*a, **kw)
         self._newStoreParentAddressBook = parentAddressBook
@@ -1674,6 +1691,9 @@
         return False
 
 
+    def name(self):
+        return self.fp.basename()
+
     def quotaSize(self, request):
         # FIXME: tests, workingness
         return succeed(0)

Modified: CalendarServer/branches/new-store/txdav/common/datastore/file.py
===================================================================
--- CalendarServer/branches/new-store/txdav/common/datastore/file.py	2010-07-13 21:51:43 UTC (rev 5885)
+++ CalendarServer/branches/new-store/txdav/common/datastore/file.py	2010-07-14 03:13:18 UTC (rev 5886)
@@ -639,13 +639,15 @@
         raise NotImplementedError
 
 
-class CommonObjectResource(LoggingMixIn):
+class CommonObjectResource(LoggingMixIn, FancyEqMixin):
     """
     @ivar _path: The path of the file on disk
 
     @type _path: L{FilePath}
     """
 
+    compareAttributes = '_name _parentCollection'.split()
+
     def __init__(self, name, parent):
         self._name = name
         self._parentCollection = parent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100713/d146b4c9/attachment-0001.html>


More information about the calendarserver-changes mailing list