def copyXAttrs(from_fp, to_fp): # Create xattr stores for each file and copy over all xattrs. xfrom = xattrPropertyStore(FakeXAttrResource(from_fp)) xto = xattrPropertyStore(FakeXAttrResource(to_fp)) for item in xfrom.list(): xto.set(xfrom.get(item))
def putWithXAttrs(stream, filepath): """ Write a file to a possibly existing path and preserve any xattrs at that path. @param stream: the stream to write to the destination. @type stream: C{file} @param filepath: the destination file. @type filepath: L{FilePath} """ # Preserve existings xattrs props = [] if filepath.exists(): xold = xattrPropertyStore(FakeXAttrResource(filepath)) for item in xold.list(): props.append((xold.get(item))) xold = None # First do the actual file copy def _gotResponse(response): # Restore original xattrs. if props: xnew = xattrPropertyStore(FakeXAttrResource(filepath)) for prop in props: xnew.set(prop) xnew = None return response d = put(stream, filepath) d.addCallback(_gotResponse) return d
def setUp(self): """ Create a resource and a xattr property store for it. """ self.resourcePath = FilePath(self.mktemp()) self.resourcePath.setContent("") self.attrs = xattr(self.resourcePath.path) self.resource = DAVFile(self.resourcePath.path) self.propertyStore = xattrPropertyStore(self.resource)
def _gotResponse(response): # Restore original xattrs. if props: xnew = xattrPropertyStore(FakeXAttrResource(filepath)) for prop in props: xnew.set(prop) xnew = None return response
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_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_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)