From 7f03c0e5b2b4da3e4c1534eefbedede3ce51de26 Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 29 Feb 2016 10:26:22 +0000 Subject: [PATCH] pybind: fix error handling on getxattr 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 --- src/pybind/cephfs/cephfs.pyx | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 95413fce0a6..712163671b9 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -703,16 +703,23 @@ cdef class LibCephFS(object): char *ret_buf = NULL try: - while True: - ret_buf = realloc_chk(ret_buf, ret_length) + ret_buf = 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 = 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) -- 2.47.3