]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/cephfs/cephfs.pyx
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / pybind / cephfs / cephfs.pyx
index def4069b90ff164c3e3ed68f74f35adb78a22835..99de1adcca9a98bead5c3fa4e3287beb48c943bb 100644 (file)
@@ -21,6 +21,7 @@ if sys.version_info[0] < 3:
 else:
     str_type = str
 
+cdef int AT_SYMLINK_NOFOLLOW = 0x100
 
 cdef extern from "Python.h":
     # These are in cpython/string.pxd, but use "object" types instead of
@@ -156,6 +157,7 @@ cdef extern from "cephfs/libcephfs.h" nogil:
     int ceph_fsync(ceph_mount_info *cmount, int fd, int syncdataonly)
     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)
     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)
@@ -840,6 +842,29 @@ 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):
+        """
+        Change directory ownership
+        :param path: the path of the directory to change.
+        :param uid: the uid to set
+        :param gid: the gid to set
+        """
+        self.require_state("mounted")
+        path = cstr(path, 'path')
+        if not isinstance(uid, int):
+            raise TypeError('uid must be an int')
+        elif not isinstance(gid, int):
+            raise TypeError('gid must be an int')
+
+        cdef:
+            char* _path = path
+            int _uid = uid
+            int _gid = gid
+        with nogil:
+            ret = ceph_chown(self.cluster, _path, _uid, _gid)
+        if ret < 0:
+            raise make_ex(ret, "error in chown {}".format(path.decode('utf-8')))
+
     def mkdirs(self, path, mode):
         """
         Create multiple directories at once.
@@ -1108,7 +1133,7 @@ cdef class LibCephFS(object):
             raise make_ex(ret, "error in setxattr")
 
 
-    def stat(self, path):
+    def stat(self, path, follow_symlink=True):
         """
         Get a file's extended statistics and attributes.
         
@@ -1121,9 +1146,15 @@ cdef class LibCephFS(object):
             char* _path = path
             statx stx
 
-        with nogil:
-            # FIXME: replace magic number with CEPH_STATX_BASIC_STATS
-            ret = ceph_statx(self.cluster, _path, &stx, 0x7ffu, 0)
+        if follow_symlink:
+            with nogil:
+                # FIXME: replace magic number with CEPH_STATX_BASIC_STATS
+                ret = ceph_statx(self.cluster, _path, &stx, 0x7ffu, 0)
+        else:
+            with nogil:
+                ret = ceph_statx(self.cluster, _path, &stx, 0x7ffu,
+                                 AT_SYMLINK_NOFOLLOW)
+
         if ret < 0:
             raise make_ex(ret, "error in stat: {}".format(path.decode('utf-8')))
         return StatResult(st_dev=stx.stx_dev, st_ino=stx.stx_ino,
@@ -1136,6 +1167,16 @@ cdef class LibCephFS(object):
                           st_mtime=datetime.fromtimestamp(stx.stx_mtime.tv_sec),
                           st_ctime=datetime.fromtimestamp(stx.stx_ctime.tv_sec))
 
+    def lstat(self, path):
+        """
+        Get a file's extended statistics and attributes. When file's a
+        symbolic link, return the informaion of the link itself rather
+        than that of the file it points too.
+
+        :param path: the file or directory to get the statistics of.
+        """
+        return self.stat(path, follow_symlink=False)
+
     def fstat(self, fd):
         """
         Get an open file's extended statistics and attributes.