Skip to content

Commit

Permalink
pybind: fix open flags calculation
Browse files Browse the repository at this point in the history
(O_WRONLY | O_RDWR) is invaild open flags

Fixes: http://tracker.ceph.com/issues/19890
Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
(cherry picked from commit 2c25c99)
  • Loading branch information
ukernel authored and smithfarm committed Jul 4, 2017
1 parent dbe8a8b commit ac9aed9
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/pybind/cephfs/cephfs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -632,16 +632,26 @@ cdef class LibCephFS(object):
if flags == '':
cephfs_flags = os.O_RDONLY
else:
access_flags = 0;
for c in flags:
if c == 'r':
cephfs_flags |= os.O_RDONLY
access_flags = 1;
elif c == 'w':
cephfs_flags |= os.O_WRONLY | os.O_TRUNC | os.O_CREAT
elif c == '+':
cephfs_flags |= os.O_RDWR
access_flags = 2;
cephfs_flags |= os.O_TRUNC | os.O_CREAT
elif access_flags > 0 and c == '+':
access_flags = 3;
else:
raise OperationNotSupported(
"open flags doesn't support %s" % c)

if access_flags == 1:
cephfs_flags |= os.O_RDONLY;
elif access_flags == 2:
cephfs_flags |= os.O_WRONLY;
else:
cephfs_flags |= os.O_RDWR;

elif isinstance(flags, int):
cephfs_flags = flags
else:
Expand Down

0 comments on commit ac9aed9

Please sign in to comment.