Commit 56c96a11 authored by Kirill Smelkov's avatar Kirill Smelkov Committed by Julien Muchembled

FileStorage: Report problem on read-only open of non-existent file

... instead of silently creating empty database on such opens.

Use-case for this are utilities like e.g. zodbdump and zodbcmp which
expect such storage opens to fail so that the tool can know there is no
such storage and report it to user.

In contrast current state is: read-only opens get created-on-the-fly
empty storage with no content, but which can be iterated over without
getting any error.

This way e.g. `zodbdump non-existent.fs` produces empty output _and_
exit code 0 which is not what caller expects.

(cherry picked from commit 30bbabf1)
parent 60ce5795
......@@ -189,6 +189,10 @@ class FileStorage(
if exc.errno == errno.EFBIG:
# The file is too big to open. Fail visibly.
if read_only:
# When open request is read-only we do not want to create
# the file
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
path %s
""" % path)
# write operations must be disallowed on read-only access
cfg = """
......@@ -711,6 +711,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
>>> 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