if ret < 0:
raise make_ex(ret, "chdir failed")
- def isdir(self, dirent):
- return dirent['d_type'] == 0x4
-
def opendir(self, path):
self.require_state("mounted")
if not isinstance(path, basestring):
cephfs_flags |= os.O_RDONLY
elif c == 'w':
cephfs_flags |= os.O_WRONLY | os.O_TRUNC | os.O_CREAT
- elif c == 'a':
- cephfs_flags |= os.O_APPEND | os.O_CREAT
elif c == '+':
cephfs_flags |= os.O_RDWR
+ else:
+ raise OperationNotSupported(
+ "open flags doesn't support %s" % c)
ret = self.libcephfs.ceph_open(self.cluster, c_char_p(path),
c_int(cephfs_flags), c_int(mode))
assert_raises(libcephfs.ObjectNotFound, cephfs.open, 'file-1', 'r')
assert_raises(libcephfs.ObjectNotFound, cephfs.open, 'file-1', 'r+')
fd = cephfs.open('file-1', 'w')
+ cephfs.write(fd, "asdf", 0)
cephfs.close(fd)
fd = cephfs.open('file-1', 'r')
+ assert_equal(cephfs.read(fd, 0, 4), "asdf")
cephfs.close(fd)
- fd = cephfs.open('file-2', 'a')
+ fd = cephfs.open('file-1', 'r+')
+ cephfs.write(fd, "zxcv", 4)
+ assert_equal(cephfs.read(fd, 4, 8), "zxcv")
cephfs.close(fd)
+ fd = cephfs.open('file-1', 'w+')
+ assert_equal(cephfs.read(fd, 0, 4), "")
+ cephfs.write(fd, "zxcv", 4)
+ assert_equal(cephfs.read(fd, 4, 8), "zxcv")
+ cephfs.close(fd)
+ assert_raises(libcephfs.OperationNotSupported, cephfs.open, 'file-1', 'a')
cephfs.unlink('file-1')
- cephfs.unlink('file-2')