[CalendarServer-changes] [5718] CalendarServer/trunk/twext/web2/dav

source_changes at macosforge.org source_changes at macosforge.org
Thu Jun 10 12:37:46 PDT 2010


Revision: 5718
          http://trac.macosforge.org/projects/calendarserver/changeset/5718
Author:   cdaboo at apple.com
Date:     2010-06-10 12:37:44 -0700 (Thu, 10 Jun 2010)
Log Message:
-----------
Skip Failure() when trying to read xattrs on non-existent file.

Modified Paths:
--------------
    CalendarServer/trunk/twext/web2/dav/test/test_xattrprops.py
    CalendarServer/trunk/twext/web2/dav/xattrprops.py

Modified: CalendarServer/trunk/twext/web2/dav/test/test_xattrprops.py
===================================================================
--- CalendarServer/trunk/twext/web2/dav/test/test_xattrprops.py	2010-06-10 19:26:24 UTC (rev 5717)
+++ CalendarServer/trunk/twext/web2/dav/test/test_xattrprops.py	2010-06-10 19:37:44 UTC (rev 5718)
@@ -71,7 +71,26 @@
         # of the EPERM failure.
         self.assertEquals(error.response.code, FORBIDDEN)
 
+    def _missingTest(self, method):
+        # Remove access to the directory containing the file so that getting
+        # extended attributes from it fails with EPERM.
+        self.resourcePath.parent().chmod(0)
+        # Make sure to restore access to it later so that it can be deleted
+        # after the test run is finished.
+        self.addCleanup(self.resourcePath.parent().chmod, 0700)
 
+        # Try to get a property from it - and fail.
+        document = self._makeValue()
+        error = self.assertRaises(
+            HTTPError,
+            getattr(self.propertyStore, method),
+            document.root_element.qname())
+
+        # Make sure that the status is FORBIDDEN, a roughly reasonable mapping
+        # of the EPERM failure.
+        self.assertEquals(error.response.code, FORBIDDEN)
+
+
     def test_getErrors(self):
         """
         If there is a problem getting the specified property (aside from the
@@ -80,7 +99,25 @@
         """
         self._forbiddenTest('get')
 
+    def test_getMissing(self):
+        """
+        Test missing file.
+        """
 
+        resourcePath = FilePath(self.mktemp())
+        resource = DAVFile(resourcePath.path)
+        propertyStore = xattrPropertyStore(resource)
+
+        # Try to get a property from it - and fail.
+        document = self._makeValue()
+        error = self.assertRaises(
+            HTTPError,
+            propertyStore.get,
+            document.root_element.qname())
+
+        # Make sure that the status is NOT FOUND.
+        self.assertEquals(error.response.code, NOT_FOUND)
+
     def _makeValue(self, uid=None):
         """
         Create and return any old WebDAVDocument for use by the get tests.
@@ -274,6 +311,19 @@
         self._forbiddenTest('contains')
 
 
+    def test_containsMissing(self):
+        """
+        Test missing file.
+        """
+
+        resourcePath = FilePath(self.mktemp())
+        resource = DAVFile(resourcePath.path)
+        propertyStore = xattrPropertyStore(resource)
+
+        # Try to get a property from it - and fail.
+        document = self._makeValue()
+        self.assertFalse(propertyStore.contains(document.root_element.qname()))
+
     def test_list(self):
         """
         L{xattrPropertyStore.list} returns a C{list} of property names
@@ -309,6 +359,18 @@
         # of the EPERM failure.
         self.assertEquals(error.response.code, FORBIDDEN)
 
+    def test_listMissing(self):
+        """
+        Test missing file.
+        """
+
+        resourcePath = FilePath(self.mktemp())
+        resource = DAVFile(resourcePath.path)
+        propertyStore = xattrPropertyStore(resource)
+
+        # Try to get a property from it - and fail.
+        self.assertEqual(propertyStore.list(), [])
+
     def test_get_uids(self):
         """
         L{xattrPropertyStore.get} accepts a L{WebDAVElement} and stores a

Modified: CalendarServer/trunk/twext/web2/dav/xattrprops.py
===================================================================
--- CalendarServer/trunk/twext/web2/dav/xattrprops.py	2010-06-10 19:26:24 UTC (rev 5717)
+++ CalendarServer/trunk/twext/web2/dav/xattrprops.py	2010-06-10 19:37:44 UTC (rev 5718)
@@ -34,6 +34,7 @@
 __all__ = ["xattrPropertyStore"]
 
 import urllib
+import os
 import sys
 import zlib
 import errno
@@ -132,6 +133,7 @@
         @return: A L{WebDAVDocument} representing the value associated with the
             given property.
         """
+        
         try:
             data = self.attrs.get(self._encode(qname, uid))
         except KeyError:
@@ -139,7 +141,7 @@
                     responsecode.NOT_FOUND,
                     "No such property: {%s}%s" % qname))
         except IOError, e:
-            if e.errno in _ATTR_MISSING:
+            if e.errno in _ATTR_MISSING or e.errno == errno.ENOENT:
                 raise HTTPError(StatusResponse(
                         responsecode.NOT_FOUND,
                         "No such property: {%s}%s" % qname))
@@ -241,6 +243,7 @@
 
         @return: C{True} if the property exists, C{False} otherwise.
         """
+            
         key = self._encode(qname, uid)
         try:
             self.attrs.get(key)
@@ -267,10 +270,13 @@
         @return: A C{list} of property names as two-tuples of namespace URI and
             local name.
         """
+            
         prefix = self.deadPropertyXattrPrefix
         try:
             attrs = iter(self.attrs)
-        except IOError:
+        except IOError, e:
+            if e.errno == errno.ENOENT:
+                return []
             raise HTTPError(
                 StatusResponse(
                     statusForFailure(Failure()),
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100610/b5b2b86f/attachment.html>


More information about the calendarserver-changes mailing list