]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pycephfs: Add rename, rmdir and getxattr support
authorHaomai Wang <haomaiwang@gmail.com>
Fri, 24 Apr 2015 15:37:13 +0000 (23:37 +0800)
committerHaomai Wang <haomaiwang@gmail.com>
Thu, 30 Apr 2015 14:06:43 +0000 (22:06 +0800)
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
src/pybind/cephfs.py

index 9f977d12bff7d4b21bd382e9ca38ef52a69c4a90..b3a00e2edc508455894ce737392f6e2228eff2e1 100644 (file)
@@ -360,6 +360,14 @@ class LibCephFS(object):
         if ret < 0:
             raise make_ex(ret, "error in mkdirs '%s'" % path)
 
+    def rmdir(self, path):
+        self.require_state("mounted")
+        if not isinstance(path, str):
+            raise TypeError('path must be a string')
+        ret = self.libcephfs.ceph_rmdir(self.cluster, c_char_p(path))
+        if ret < 0:
+            raise make_ex(ret, "error in rmdir '%s'" % path)
+
     def open(self, path, flags, mode):
         self.require_state("mounted")
         if not isinstance(path, str):
@@ -379,6 +387,20 @@ class LibCephFS(object):
         if ret < 0:
             raise make_ex(ret, "error in close")
 
+    def getxattr(self, path, name):
+        if not isinstance(path, str):
+            raise TypeError('path must be a string')
+        if not isinstance(name, str):
+            raise TypeError('name must be a string')
+
+        l = 255
+        buf = create_string_buffer(l)
+        actual_l = self.libcephfs.ceph_getxattr(self.cluster, path, name, buf, c_int(l))
+        if actual_l > l:
+            buf = create_string_buffer(actual_)
+            self.libcephfs.ceph_getxattr(path, name, new_buf, actual_l)
+        return buf.value
+
     def setxattr(self, path, name, value, flags):
         if not isinstance(path, str):
             raise TypeError('path must be a string')
@@ -424,6 +446,14 @@ class LibCephFS(object):
         if ret < 0:
             raise make_ex(ret, "error in unlink: %s" % path)
 
+    def rename(self, src, dst):
+        self.require_state("mounted")
+        if not isinstance(src, str) or not isinstance(dst, str):
+            raise TypeError('source and destination must be a string')
+        ret = self.libcephfs.ceph_rename(self.cluster, c_char_p(src), c_char_p(dst))
+        if ret < 0:
+            raise make_ex(ret, "error in rename '%s' to '%s'" % (src, dst))
+
     def mds_command(self, mds_spec, args, input_data):
         """
         :return 3-tuple of output status int, output status string, output data