def open(self, path, flags, mode=0):
self.require_state("mounted")
-
path = cstr(path, 'path')
- flags = cstr(flags, 'flags')
+
if not isinstance(mode, int):
raise TypeError('mode must be an int')
- cephfs_flags = 0
- if flags == '':
- cephfs_flags = os.O_RDONLY
+ if isinstance(flags, basestring):
+ flags = cstr(flags, 'flags')
+ cephfs_flags = 0
+ if flags == '':
+ cephfs_flags = os.O_RDONLY
+ else:
+ for c in flags:
+ if c == 'r':
+ cephfs_flags |= os.O_RDONLY
+ elif c == 'w':
+ cephfs_flags |= os.O_WRONLY | os.O_TRUNC | os.O_CREAT
+ elif c == '+':
+ cephfs_flags |= os.O_RDWR
+ else:
+ raise OperationNotSupported(
+ "open flags doesn't support %s" % c)
+ elif isinstance(flags, int):
+ cephfs_flags = flags
else:
- for c in flags:
- if c == 'r':
- cephfs_flags |= os.O_RDONLY
- elif c == 'w':
- cephfs_flags |= os.O_WRONLY | os.O_TRUNC | os.O_CREAT
- elif c == '+':
- cephfs_flags |= os.O_RDWR
- else:
- raise OperationNotSupported(
- "open flags doesn't support %s" % c)
+ raise TypeError("flags must be a string or an integer")
cdef:
char* _path = path
from nose.tools import assert_raises, assert_equal, with_setup
import cephfs as libcephfs
import fcntl
+import os
cephfs = None
cephfs.write(fd, "zxcv", 4)
assert_equal(cephfs.read(fd, 4, 8), "zxcv")
cephfs.close(fd)
+ fd = cephfs.open('file-1', os.O_RDWR, 0755)
+ cephfs.write(fd, "asdf", 0)
+ assert_equal(cephfs.read(fd, 0, 4), "asdf")
+ cephfs.close(fd)
assert_raises(libcephfs.OperationNotSupported, cephfs.open, 'file-1', 'a')
cephfs.unlink('file-1')