]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: fix error handling on getxattr
authorJohn Spray <john.spray@redhat.com>
Mon, 29 Feb 2016 10:26:22 +0000 (10:26 +0000)
committerMehdi Abaakouk <sileht@redhat.com>
Mon, 29 Feb 2016 10:36:40 +0000 (11:36 +0100)
The ctypes bindings returned empty string
instead of raising exception.  This was a bug,
because it made it impossible to detect the
difference between missing xattr and empty
xattr.

Signed-off-by: John Spray <john.spray@redhat.com>
src/pybind/cephfs/cephfs.pyx

index 95413fce0a6c938083977df8d8919ff0904e65b5..712163671b98d0ea5bc5c717bc9aa219960c631b 100644 (file)
@@ -703,16 +703,23 @@ cdef class LibCephFS(object):
             char *ret_buf = NULL
 
         try:
-            while True:
-                ret_buf = <char *>realloc_chk(ret_buf, ret_length)
+            ret_buf = <char *>realloc_chk(ret_buf, ret_length)
+            with nogil:
+                ret = ceph_getxattr(self.cluster, _path, _name, ret_buf,
+                                    ret_length)
+
+            if ret < 0:
+                raise make_ex(ret, "error in getxattr")
+
+            if ret > ret_length:
+                ret_buf = <char *>realloc_chk(ret_buf, ret)
                 with nogil:
-                    ret = ceph_getxattr(self.cluster, _path, _name, ret_buf, ret_length)
+                    ret = ceph_getxattr(self.cluster, _path, _name, ret_buf,
+                                        ret)
                 if ret < 0:
                     raise make_ex(ret, "error in getxattr")
-                elif ret > ret_length:
-                    ret_length = ret
-                else:
-                    return ret_buf[:ret]
+
+            return ret_buf[:ret]
         finally:
             free(ret_buf)