diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2004-06-27 22:56:42 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2004-06-27 22:56:42 (GMT) |
commit | a6b3caad417c0472b611be251d623331744079a5 (patch) | |
tree | 5534ce554ac126c4f804b1d8b49e432086268a6d /Lib/bsddb/__init__.py | |
parent | e7c053233fa4a0f9a1ddfe96b5a3ea57495f9882 (diff) | |
download | cpython-a6b3caad417c0472b611be251d623331744079a5.zip cpython-a6b3caad417c0472b611be251d623331744079a5.tar.gz cpython-a6b3caad417c0472b611be251d623331744079a5.tar.bz2 |
Fix SF bug # 897820 - we can no longer use the DB_TRUNCATE flag when
opening the DB to implement legacy interface flag='n' support as
BerkeleyDB 4.2.52 no longer allows it in transaction protected
environments. Do the os.unlink ourselves.
Diffstat (limited to 'Lib/bsddb/__init__.py')
-rw-r--r-- | Lib/bsddb/__init__.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/Lib/bsddb/__init__.py b/Lib/bsddb/__init__.py index 90bf92b..3ee3441 100644 --- a/Lib/bsddb/__init__.py +++ b/Lib/bsddb/__init__.py @@ -59,7 +59,7 @@ error = db.DBError # So bsddb.error will mean something... #---------------------------------------------------------------------- -import sys +import sys, os # for backwards compatibility with python versions older than 2.3, the # iterator interface is dynamically defined and added using a mixin @@ -281,7 +281,7 @@ class _DBWithCursor(_iter_mixin): def hashopen(file, flag='c', mode=0666, pgsize=None, ffactor=None, nelem=None, cachesize=None, lorder=None, hflags=0): - flags = _checkflag(flag) + flags = _checkflag(flag, file) e = _openDBEnv() d = db.DB(e) d.set_flags(hflags) @@ -299,7 +299,7 @@ def btopen(file, flag='c', mode=0666, btflags=0, cachesize=None, maxkeypage=None, minkeypage=None, pgsize=None, lorder=None): - flags = _checkflag(flag) + flags = _checkflag(flag, file) e = _openDBEnv() d = db.DB(e) if cachesize is not None: d.set_cachesize(0, cachesize) @@ -318,7 +318,7 @@ def rnopen(file, flag='c', mode=0666, rnflags=0, cachesize=None, pgsize=None, lorder=None, rlen=None, delim=None, source=None, pad=None): - flags = _checkflag(flag) + flags = _checkflag(flag, file) e = _openDBEnv() d = db.DB(e) if cachesize is not None: d.set_cachesize(0, cachesize) @@ -339,7 +339,7 @@ def _openDBEnv(): e.open('.', db.DB_PRIVATE | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_LOCK | db.DB_INIT_MPOOL) return e -def _checkflag(flag): +def _checkflag(flag, file): if flag == 'r': flags = db.DB_RDONLY elif flag == 'rw': @@ -349,7 +349,12 @@ def _checkflag(flag): elif flag == 'c': flags = db.DB_CREATE elif flag == 'n': - flags = db.DB_CREATE | db.DB_TRUNCATE + flags = db.DB_CREATE + #flags = db.DB_CREATE | db.DB_TRUNCATE + # we used db.DB_TRUNCATE flag for this before but BerkeleyDB + # 4.2.52 changed to disallowed truncate with txn environments. + if os.path.isfile(file): + os.unlink(file) else: raise error, "flags should be one of 'r', 'w', 'c' or 'n'" return flags | db.DB_THREAD |