]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephfs.pyx: handle when UID/GID passed to chown() is -1
authorRishabh Dave <ridave@redhat.com>
Tue, 12 Aug 2025 16:41:23 +0000 (22:11 +0530)
committerRishabh Dave <ridave@redhat.com>
Wed, 13 Aug 2025 04:47:54 +0000 (10:17 +0530)
When chown() in libcephfs call receives -1 as the value of UID/GID, it
is implicitly converted from signed integer to unsigned integeer but
CephFS cython instead of doing that errors out during complilation.
Therefore make this conversion explicitly to allow users to pass -1
(which they do to indicate that UID/GID value shouldn't be changed) and
also for sake of uniformity and consistency between between CephFS
cython and libcephfs interface.

Fixes: https://tracker.ceph.com/issues/72547
Introduced-by: 65328aca31f2f5038cb602148120b9427370ed4f
Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/pybind/cephfs/cephfs.pyx

index fb81732bea9829e09a6d6d7050c6c6d177863f7c..4410015a0152b1213d0367e16c7e0e61ccc414c4 100644 (file)
@@ -1293,8 +1293,10 @@ cdef class LibCephFS(object):
 
         cdef:
             char* _path = path
-            uid_t _uid = uid
-            gid_t _gid = gid
+            # Avoid "OverflowError: can't convert negative value to uid_t."
+            uid_t _uid = uid if uid >= 0 else -1
+            # Avoid "OverflowError: can't convert negative value to gid_t."
+            gid_t _gid = gid if gid >= 0 else -1
         if follow_symlink:
             with nogil:
                 ret = ceph_chown(self.cluster, _path, _uid, _gid)
@@ -1332,8 +1334,10 @@ cdef class LibCephFS(object):
 
         cdef:
             int _fd = fd
-            uid_t _uid = uid
-            gid_t _gid = gid
+            # Avoid "OverflowError: can't convert negative value to uid_t."
+            uid_t _uid = uid if uid >= 0 else -1
+            # Avoid "OverflowError: can't convert negative value to gid_t."
+            gid_t _gid = gid if gid >= 0 else -1
         with nogil:
             ret = ceph_fchown(self.cluster, _fd, _uid, _gid)
         if ret < 0: