Exemplo n.º 1
0
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))
Exemplo n.º 2
0
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
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 def _gotResponse(response):
 
     # Restore original xattrs.
     if props:
         xnew = xattrPropertyStore(FakeXAttrResource(filepath))
         for prop in props:
             xnew.set(prop)
         xnew = None
 
     return response
Exemplo n.º 5
0
    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(), [])
Exemplo n.º 6
0
    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()))
Exemplo n.º 7
0
    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)