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
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)
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.
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.
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,
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.