From f7b821963c4d548cb84dfc2942c0f49b896eed7a Mon Sep 17 00:00:00 2001 From: Jan Malakhovski Date: Sun, 1 Jul 2018 22:34:34 +0000 Subject: [PATCH] Fix read-only support --- semidbm/compat.py | 2 ++ semidbm/db.py | 8 ++++++++ test_semidbm.py | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/semidbm/compat.py b/semidbm/compat.py index 3785353..ab1486f 100644 --- a/semidbm/compat.py +++ b/semidbm/compat.py @@ -16,8 +16,10 @@ DATA_OPEN_FLAGS = os.O_RDWR | os.O_CREAT | os.O_APPEND +DATA_OPENRO_FLAGS = os.O_RDONLY if sys.platform.startswith('win'): # On windows we need to specify that we should be # reading the file as a binary file so it doesn't # change any line ending characters. DATA_OPEN_FLAGS = DATA_OPEN_FLAGS | os.O_BINARY + DATA_OPENRO_FLAGS = DATA_OPENRO_FLAGS | os.O_BINARY diff --git a/semidbm/db.py b/semidbm/db.py index 5530508..057fed2 100644 --- a/semidbm/db.py +++ b/semidbm/db.py @@ -237,6 +237,14 @@ def __delitem__(self, key): def __setitem__(self, key, value): self._method_not_allowed('setitem') + def _load_db(self): + self._index = self._load_index(self._data_filename) + self._data_fd = os.open(self._data_filename, compat.DATA_OPENRO_FLAGS) + self._current_offset = os.lseek(self._data_fd, 0, os.SEEK_END) + + def _write_headers(self, filename): + pass + def sync(self): self._method_not_allowed('sync') diff --git a/test_semidbm.py b/test_semidbm.py index 08218c8..9cc7e67 100644 --- a/test_semidbm.py +++ b/test_semidbm.py @@ -374,6 +374,11 @@ def test_remap_required(self): class TestReadOnlyMode(SemiDBMTest): + def setUp(self): + super(TestReadOnlyMode, self).setUp() + db = semidbm.open(self.dbdir, 'c') + db.close() + def open_db_file(self, **kwargs): return semidbm.open(self.dbdir, 'r', **kwargs)