Skip to content

Commit

Permalink
Merge pull request #153 from navytux/y/fs-ro
Browse files Browse the repository at this point in the history
FileStorage: Report problem on read-only open of non-existent file
  • Loading branch information
jimfulton committed Apr 2, 2017
2 parents 3a8efe4 + 30bbabf commit 4fa9336
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ZODB/FileStorage/FileStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ def __init__(self, file_name, create=False, read_only=False, stop=None,
if exc.errno == errno.EFBIG:
# The file is too big to open. Fail visibly.
raise
if read_only:
# When open request is read-only we do not want to create
# the file
raise
if exc.errno == errno.ENOENT:
# The file doesn't exist. Create it.
create = 1
Expand Down
10 changes: 10 additions & 0 deletions src/ZODB/tests/testConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ def test_file_config1(self):

def test_file_config2(self):
path = tempfile.mktemp()
# first pass to actually create database file
self._test(
"""
<zodb>
<filestorage>
path %s
</filestorage>
</zodb>
""" % path)
# write operations must be disallowed on read-only access
cfg = """
<zodb>
<filestorage>
Expand Down
13 changes: 13 additions & 0 deletions src/ZODB/tests/testFileStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,19 @@ def pack_with_open_blob_files():
>>> db.close()
"""

def readonly_open_nonexistent_file():
"""
Make sure error is reported when non-existent file is tried to be opened
read-only.
>>> try:
... fs = ZODB.FileStorage.FileStorage('nonexistent.fs', read_only=True)
... except Exception as e:
... # Python2 raises IOError; Python3 - FileNotFoundError
... print("error: %s" % str(e)) # doctest: +ELLIPSIS
error: ... No such file or directory: 'nonexistent.fs'
"""

def test_suite():
suite = unittest.TestSuite()
for klass in [
Expand Down

0 comments on commit 4fa9336

Please sign in to comment.