Commit 7b40f55b authored by Chrysostomos Nanakos's avatar Chrysostomos Nanakos
Browse files

pithos: Add new access mode flag to file context manager

Remove old create flag that was used for choosing the access mode.
New flag 'oflag' determines the mode in which the file has to be
opened, i.e., read, write or both. Applications shall specify exactly
one of the first three values (file access modes) below in the value
of oflag:

O_RDONLY: Open for reading only
O_WRONLY: Open for writing only
O_RDWR: Open for reading and writing
parent 2547b28a
......@@ -31,9 +31,13 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from os import SEEK_CUR, SEEK_SET
from errno import ENOENT, EROFS
from os import (
_zeros = ''
......@@ -131,25 +135,24 @@ def file_sync_read_chunks(openfile, chunksize, nr, offset=0):
class ContextFile(object):
__slots__ = ("name", "fdesc", "create")
__slots__ = ("name", "fdesc", "oflag")
def __init__(self, name, create=0):
def __init__(self, name, oflag): = name
self.fdesc = None
self.create = create
self.oflag = oflag
#self.dirty = 0
def __enter__(self):
name =
fdesc = open(name, 'rb+')
except IOError, e:
if self.create and e.errno == ENOENT:
fdesc = open(name, 'w+')
elif not self.create and e.errno == EROFS:
fdesc = open(name, 'rb')
if self.oflag == O_RDONLY:
fdesc = open(name, 'rb')
elif self.oflag == O_WRONLY:
fdesc = open(name, 'wb')
elif self.oflag == O_RDWR:
fdesc = open(name, 'wb+')
raise Exception("Wrong file acccess mode.")
self.fdesc = fdesc
return self
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment