Commit 4fa93367 authored by Jim Fulton's avatar Jim Fulton Committed by GitHub

Merge pull request #153 from navytux/y/fs-ro

FileStorage: Report problem on read-only open of non-existent file
parents 3a8efe47 30bbabf1
......@@ -267,6 +267,10 @@ class FileStorage(
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
......
......@@ -73,6 +73,16 @@ class ZODBConfigTest(ConfigTestBase):
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>
......
......@@ -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 [
......
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