[CalendarServer-changes] [628] CalendarServer/branches/users/wsanchez/provisioning-2/twistedcaldav/ directory/principal.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Nov 30 23:41:29 PST 2006


Revision: 628
          http://trac.macosforge.org/projects/calendarserver/changeset/628
Author:   wsanchez at apple.com
Date:     2006-11-30 23:41:28 -0800 (Thu, 30 Nov 2006)

Log Message:
-----------
Have the resources auto-provision themselves, rather than relying on the parent.
Make the server robust against deleted parts of the principals hierarchy.

Modified Paths:
--------------
    CalendarServer/branches/users/wsanchez/provisioning-2/twistedcaldav/directory/principal.py

Modified: CalendarServer/branches/users/wsanchez/provisioning-2/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/branches/users/wsanchez/provisioning-2/twistedcaldav/directory/principal.py	2006-12-01 06:39:21 UTC (rev 627)
+++ CalendarServer/branches/users/wsanchez/provisioning-2/twistedcaldav/directory/principal.py	2006-12-01 07:41:28 UTC (rev 628)
@@ -72,19 +72,18 @@
         # FIXME: Smells like a hack
         directory.principalCollection = self
 
+        self.provision()
+
         # Create children
-        for name in self.directory.recordTypes():
-            child_fp = self.fp.child(name)
-            if child_fp.exists():
-                assert child_fp.isdir()
-            else:
-                assert self.exists()
-                assert self.isCollection()
+        for recordType in self.directory.recordTypes():
+            self.putChild(recordType, DirectoryPrincipalTypeResource(self.fp.child(recordType).path, self, recordType))
 
-                child_fp.makedirs()
+    def provision(self):
+        self.fp.restat(False)
+        if not self.fp.exists():
+            self.fp.makedirs()
+            self.fp.restat(False)
 
-            self.putChild(name, DirectoryPrincipalTypeResource(child_fp.path, self, name))
-
     def principalForUser(self, user):
         return self.getChild("user").getChild(user)
 
@@ -102,11 +101,14 @@
         raise HTTPError(responsecode.NOT_FOUND)
 
     def getChild(self, name):
-        # This avoids finding case variants of put children on case-insensitive filesystems.
-        if name not in self.putChildren and name.lower() in (x.lower() for x in self.putChildren):
+        self.provision()
+
+        children = self.putChildren
+        if name not in children and name.lower() in (x.lower() for x in children):
+            # This avoids finding case variants of put children on case-insensitive filesystems.
             return None
         else:
-            return self.putChildren.get(name, None)
+            return children.get(name, None)
 
     def listChildren(self):
         return self.putChildren.keys()
@@ -135,6 +137,16 @@
         self.recordType = recordType
         self._parent = parent
 
+        self.provision()
+
+    def provision(self):
+        self.fp.restat(False)
+        if not self.fp.exists():
+            assert self._parent.exists()
+            assert self._parent.isCollection()
+            self.fp.makedirs()
+            self.fp.restat(False)
+
     def principalForUser(self, user):
         return self._parent.principalForUser(user)
 
@@ -149,6 +161,8 @@
         raise HTTPError(responsecode.NOT_FOUND)
 
     def getChild(self, name, record=None):
+        self.provision()
+
         if name == "":
             return self
 
@@ -160,17 +174,8 @@
             assert name is None
             name = record.shortName
 
-        child_fp = self.fp.child(name)
-        if child_fp.exists():
-            assert child_fp.isfile()
-        else:
-            assert self.exists()
-            assert self.isCollection()
+        return DirectoryPrincipalResource(self.fp.child(name).path, self, record)
 
-            child_fp.open("w").close()
-
-        return DirectoryPrincipalResource(child_fp.path, self, record)
-
     def listChildren(self):
         return (record.shortName for record in self.directory.listRecords(self.recordType))
 
@@ -191,6 +196,16 @@
         self.record = record
         self._parent = parent
 
+        self.provision()
+
+    def provision(self):
+        self.fp.restat(False)
+        if not self.fp.exists():
+            assert self._parent.exists()
+            assert self._parent.isCollection()
+            self.fp.open("w").close()
+            self.fp.restat(False)
+
     ##
     # HTTP
     ##

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20061130/a4c67157/attachment.html


More information about the calendarserver-changes mailing list