]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/cephfs: pybind call for changing ownership for symlinks
authorVenky Shankar <vshankar@redhat.com>
Wed, 5 Feb 2020 04:18:55 +0000 (23:18 -0500)
committerRamana Raja <rraja@redhat.com>
Thu, 12 Mar 2020 07:20:16 +0000 (12:50 +0530)
Signed-off-by: Venky Shankar <vshankar@redhat.com>
(cherry picked from commit ea97410fb796afc4ac8d522003dae5a278c3f96f)

src/pybind/cephfs/cephfs.pyx

index 99de1adcca9a98bead5c3fa4e3287beb48c943bb..aa5390ef3e121d096ad7bae3bf5f3b9afe81883a 100644 (file)
@@ -158,6 +158,7 @@ cdef extern from "cephfs/libcephfs.h" nogil:
     int ceph_conf_parse_argv(ceph_mount_info *cmount, int argc, const char **argv)
     int ceph_chmod(ceph_mount_info *cmount, const char *path, mode_t mode)
     int ceph_chown(ceph_mount_info *cmount, const char *path, int uid, int gid)
+    int ceph_lchown(ceph_mount_info *cmount, const char *path, int uid, int gid)
     int64_t ceph_lseek(ceph_mount_info *cmount, int fd, int64_t offset, int whence)
     void ceph_buffer_free(char *buf)
     mode_t ceph_umask(ceph_mount_info *cmount, mode_t mode)
@@ -842,12 +843,14 @@ cdef class LibCephFS(object):
         if ret < 0:
             raise make_ex(ret, "error in chmod {}".format(path.decode('utf-8')))
 
-    def chown(self, path, uid, gid):
+    def chown(self, path, uid, gid, follow_symlink=True):
         """
         Change directory ownership
         :param path: the path of the directory to change.
         :param uid: the uid to set
         :param gid: the gid to set
+        :param follow_symlink: perform the operation on the target file if @path
+                               is a symbolic link (default)
         """
         self.require_state("mounted")
         path = cstr(path, 'path')
@@ -860,11 +863,24 @@ cdef class LibCephFS(object):
             char* _path = path
             int _uid = uid
             int _gid = gid
-        with nogil:
-            ret = ceph_chown(self.cluster, _path, _uid, _gid)
+        if follow_symlink:
+            with nogil:
+                ret = ceph_chown(self.cluster, _path, _uid, _gid)
+        else:
+            with nogil:
+                ret = ceph_lchown(self.cluster, _path, _uid, _gid)
         if ret < 0:
             raise make_ex(ret, "error in chown {}".format(path.decode('utf-8')))
 
+    def lchown(self, path, uid, gid):
+        """
+        Change ownership of a symbolic link
+        :param path: the path of the symbolic link to change.
+        :param uid: the uid to set
+        :param gid: the gid to set
+        """
+        self.chown(path, uid, gid, follow_symlink=False)
+
     def mkdirs(self, path, mode):
         """
         Create multiple directories at once.