[CalendarServer-changes] [5950] CalendarServer/branches/new-store-no-caldavfile-2

source_changes at macosforge.org source_changes at macosforge.org
Mon Jul 26 14:40:37 PDT 2010


Revision: 5950
          http://trac.macosforge.org/projects/calendarserver/changeset/5950
Author:   glyph at apple.com
Date:     2010-07-26 14:40:37 -0700 (Mon, 26 Jul 2010)
Log Message:
-----------
on-demand path calculation for sharing indexes and and notification collection

Modified Paths:
--------------
    CalendarServer/branches/new-store-no-caldavfile-2/txcaldav/calendarstore/file.py
    CalendarServer/branches/new-store-no-caldavfile-2/txdav/common/datastore/file.py

Modified: CalendarServer/branches/new-store-no-caldavfile-2/txcaldav/calendarstore/file.py
===================================================================
--- CalendarServer/branches/new-store-no-caldavfile-2/txcaldav/calendarstore/file.py	2010-07-26 21:39:55 UTC (rev 5949)
+++ CalendarServer/branches/new-store-no-caldavfile-2/txcaldav/calendarstore/file.py	2010-07-26 21:40:37 UTC (rev 5950)
@@ -385,12 +385,12 @@
         if attachProperty is not None:
             # Make sure the value type is URI
             valueType = attachProperty.params().get("VALUE", ("TEXT",))
-            if valueType[0] == "URI": 
+            if valueType[0] == "URI":
                 # FIXME: more aggressive checking to see if this URI is really the
                 # 'right' URI.  Maybe needs to happen in the front end.
                 attachPath = attachProperty.value().split("/")[-2]
                 return attachPath
-        
+
         return self.uid() + ".dropbox"
 
 
@@ -521,11 +521,17 @@
 
     def __init__(self, calendar):
         self.calendar = calendar
-        self.fp = self.calendar._path
 
+
+    @property
+    def fp(self):
+        return self.calendar._path
+
+
     def isCalendarCollection(self):
         return True
 
+
     def getChild(self, name):
         calendarObject = self.calendar.calendarObjectWithName(name)
         if calendarObject:
@@ -540,6 +546,7 @@
         else:
             return None
 
+
     def bumpSyncToken(self, reset=False):
         # FIXME: needs direct tests
         return self.calendar._updateSyncToken(reset)
@@ -549,6 +556,8 @@
         # FIXME: needs direct tests
         self.bumpSyncToken(True)
 
+
+
 class Index(object):
     #
     # OK, here's where we get ugly.

Modified: CalendarServer/branches/new-store-no-caldavfile-2/txdav/common/datastore/file.py
===================================================================
--- CalendarServer/branches/new-store-no-caldavfile-2/txdav/common/datastore/file.py	2010-07-26 21:39:55 UTC (rev 5949)
+++ CalendarServer/branches/new-store-no-caldavfile-2/txdav/common/datastore/file.py	2010-07-26 21:40:37 UTC (rev 5950)
@@ -174,13 +174,9 @@
                 homePath = childPath.temporarySibling()
                 createDirectory(homePath)
                 def do():
-                    def lastly():
-                        homePath.moveTo(childPath)
-                        # home._path = homePath
-                        # do this _after_ all other file operations
-                        home._path = childPath
-                        return lambda : None
-                    self.addOperation(lastly, "create home finalize")
+                    homePath.moveTo(childPath)
+                    # do this _after_ all other file operations
+                    home._path = childPath
                     return lambda : None
                 self.addOperation(do, "create home UID %r" % (uid,))
 
@@ -208,56 +204,62 @@
         if (uid, self) in self._notifications:
             return self._notifications[(uid, self)]
 
-        notificationPath = home._path.child("notification")
-        if not notificationPath.isdir():
-            notifications = self.createNotifcationCollection(home, notificationPath)
+        notificationCollectionName = "notification"
+        if not home._path.child(notificationCollectionName).isdir():
+            notifications = self._createNotificationCollection(home, notificationCollectionName)
         else:
-            notifications = NotificationCollection(notificationPath.basename(), home)
+            notifications = NotificationCollection(notificationCollectionName, home)
         self._notifications[(uid, self)] = notifications
         return notifications
 
-    def createNotifcationCollection(self, home, notificationPath):
 
-        if notificationPath.isdir():
-            return notificationPath
-
-        name = notificationPath.basename()
-
-        temporary = hidden(notificationPath.temporarySibling())
+    def _createNotificationCollection(self, home, collectionName):
+        # FIXME: this is a near-copy of CommonHome.createChildWithName.
+        temporary = hidden(home._path.child(collectionName).temporarySibling())
         temporary.createDirectory()
-        # In order for the index to work (which is doing real file ops on disk
-        # via SQLite) we need to create a real directory _immediately_.
+        temporaryName = temporary.basename()
 
-        # FIXME: some way to roll this back.
+        c = NotificationCollection(temporary.basename(), home)
 
-        c = NotificationCollection(temporary.basename(), home)
         def do():
+            childPath = home._path.child(collectionName)
+            temporary = childPath.sibling(temporaryName)
             try:
                 props = c.properties()
-                temporary.moveTo(notificationPath)
-                c._name = name
+                temporary.moveTo(childPath)
+                c._name = collectionName
                 # FIXME: _lots_ of duplication of work here.
                 props.flush()
             except (IOError, OSError), e:
-                if e.errno == EEXIST and notificationPath.isdir():
-                    raise HomeChildNameAlreadyExistsError(name)
+                if e.errno == EEXIST and childPath.isdir():
+                    raise HomeChildNameAlreadyExistsError(collectionName)
                 raise
             # FIXME: direct tests, undo for index creation
             # Return undo
-            return lambda: home._path.child(notificationPath.basename()).remove()
+            return lambda: home._path.child(collectionName).remove()
 
-        self.addOperation(do, "create child %r" % (name,))
+        self.addOperation(do, "create notification child %r" %
+                          (collectionName,))
         props = c.properties()
         props[PropertyName(*ResourceType.qname())] = c.resourceType()
         return c
 
+
+
 class StubResource(object):
     """
     Just enough resource to keep the shared sql DB classes going.
     """
-    def __init__(self, stubit):
-        self.fp = stubit._path
+    def __init__(self, commonHome):
+        self._commonHome = commonHome
 
+
+    @property
+    def fp(self):
+        return self._commonHome._path
+
+
+
 class CommonHome(FileMetaDataMixin, LoggingMixIn):
 
     _childClass = None
@@ -280,9 +282,11 @@
     def uid(self):
         return self._uid
 
+
     def peruser_uid(self):
         return self._peruser_uid
 
+
     def _updateSyncToken(self, reset=False):
         "Stub for updating sync token."
         # FIXME: actually update something
@@ -294,6 +298,7 @@
         """
         return self._shares
 
+
     def children(self):
         """
         Return a set of the child resource objects.
@@ -304,6 +309,7 @@
             if not name.startswith(".")
         )
 
+
     def listChildren(self):
         """
         Return a set of the names of the child resources.
@@ -316,6 +322,7 @@
             if not name.startswith(".")
         ))
 
+
     def childWithName(self, name):
         child = self._newChildren.get(name)
         if child is not None:
@@ -348,6 +355,7 @@
             raise HomeChildNameAlreadyExistsError(name)
 
         temporary = hidden(childPath.temporarySibling())
+        temporaryName = temporary.basename()
         temporary.createDirectory()
         # In order for the index to work (which is doing real file ops on disk
         # via SQLite) we need to create a real directory _immediately_.
@@ -357,6 +365,8 @@
         c = self._newChildren[name] = self._childClass(temporary.basename(), self, name)
         c.retrieveOldIndex().create()
         def do():
+            childPath = self._path.child(name)
+            temporary = childPath.sibling(temporaryName)
             try:
                 props = c.properties()
                 temporary.moveTo(childPath)
@@ -376,9 +386,11 @@
         props[PropertyName(*ResourceType.qname())] = c.resourceType()
         self.createdChild(c)
 
+
     def createdChild(self, child):
         pass
 
+
     @writeOperation
     def removeChildWithName(self, name):
         if name.startswith(".") or name in self._removedChildren:
@@ -422,6 +434,7 @@
             do, "prepare child remove %r" % (name,)
         )
 
+
     # @cached
     def properties(self):
         # FIXME: needs tests for actual functionality
@@ -433,6 +446,7 @@
         return props
 
 
+
 class CommonHomeChild(FileMetaDataMixin, LoggingMixIn, FancyEqMixin):
     """
     """
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100726/85e48f1c/attachment-0001.html>


More information about the calendarserver-changes mailing list