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.
This commit is contained in:
Gregory P. Smith 2004-06-27 22:56:42 +00:00
parent e7c053233f
commit a6b3caad41
1 changed files with 11 additions and 6 deletions

View File

@ -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