From 5b20c40268e85abeb56f44a196976e4a6fd887d5 Mon Sep 17 00:00:00 2001 From: Antony Chazapis Date: Mon, 2 Apr 2012 13:26:23 +0300 Subject: [PATCH] Open files in backend as read-only if such is the filesystem. --- .../pithos/backends/lib/hashfiler/context_file.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/snf-pithos-backend/pithos/backends/lib/hashfiler/context_file.py b/snf-pithos-backend/pithos/backends/lib/hashfiler/context_file.py index 67894f2..adaaae4 100644 --- a/snf-pithos-backend/pithos/backends/lib/hashfiler/context_file.py +++ b/snf-pithos-backend/pithos/backends/lib/hashfiler/context_file.py @@ -32,7 +32,7 @@ # or implied, of GRNET S.A. from os import SEEK_CUR, SEEK_SET, fsync -from errno import ENOENT +from errno import ENOENT, EROFS _zeros = '' @@ -144,9 +144,12 @@ class ContextFile(object): try: fdesc = open(name, 'rb+') except IOError, e: - if not self.create or e.errno != ENOENT: + if self.create and e.errno == ENOENT: + fdesc = open(name, 'w+') + elif not self.create and e.errno == EROFS: + fdesc = open(name, 'rb') + else: raise - fdesc = open(name, 'w+') self.fdesc = fdesc return self -- 1.7.10.4