Commit a6b3caad authored by Gregory P. Smith's avatar Gregory P. Smith

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.
parent e7c05323
...@@ -59,7 +59,7 @@ error = db.DBError # So bsddb.error will mean something... ...@@ -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 # for backwards compatibility with python versions older than 2.3, the
# iterator interface is dynamically defined and added using a mixin # iterator interface is dynamically defined and added using a mixin
...@@ -281,7 +281,7 @@ class _DBWithCursor(_iter_mixin): ...@@ -281,7 +281,7 @@ class _DBWithCursor(_iter_mixin):
def hashopen(file, flag='c', mode=0666, pgsize=None, ffactor=None, nelem=None, def hashopen(file, flag='c', mode=0666, pgsize=None, ffactor=None, nelem=None,
cachesize=None, lorder=None, hflags=0): cachesize=None, lorder=None, hflags=0):
flags = _checkflag(flag) flags = _checkflag(flag, file)
e = _openDBEnv() e = _openDBEnv()
d = db.DB(e) d = db.DB(e)
d.set_flags(hflags) d.set_flags(hflags)
...@@ -299,7 +299,7 @@ def btopen(file, flag='c', mode=0666, ...@@ -299,7 +299,7 @@ def btopen(file, flag='c', mode=0666,
btflags=0, cachesize=None, maxkeypage=None, minkeypage=None, btflags=0, cachesize=None, maxkeypage=None, minkeypage=None,
pgsize=None, lorder=None): pgsize=None, lorder=None):
flags = _checkflag(flag) flags = _checkflag(flag, file)
e = _openDBEnv() e = _openDBEnv()
d = db.DB(e) d = db.DB(e)
if cachesize is not None: d.set_cachesize(0, cachesize) if cachesize is not None: d.set_cachesize(0, cachesize)
...@@ -318,7 +318,7 @@ def rnopen(file, flag='c', mode=0666, ...@@ -318,7 +318,7 @@ def rnopen(file, flag='c', mode=0666,
rnflags=0, cachesize=None, pgsize=None, lorder=None, rnflags=0, cachesize=None, pgsize=None, lorder=None,
rlen=None, delim=None, source=None, pad=None): rlen=None, delim=None, source=None, pad=None):
flags = _checkflag(flag) flags = _checkflag(flag, file)
e = _openDBEnv() e = _openDBEnv()
d = db.DB(e) d = db.DB(e)
if cachesize is not None: d.set_cachesize(0, cachesize) if cachesize is not None: d.set_cachesize(0, cachesize)
...@@ -339,7 +339,7 @@ def _openDBEnv(): ...@@ -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) e.open('.', db.DB_PRIVATE | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_LOCK | db.DB_INIT_MPOOL)
return e return e
def _checkflag(flag): def _checkflag(flag, file):
if flag == 'r': if flag == 'r':
flags = db.DB_RDONLY flags = db.DB_RDONLY
elif flag == 'rw': elif flag == 'rw':
...@@ -349,7 +349,12 @@ def _checkflag(flag): ...@@ -349,7 +349,12 @@ def _checkflag(flag):
elif flag == 'c': elif flag == 'c':
flags = db.DB_CREATE flags = db.DB_CREATE
elif flag == 'n': 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: else:
raise error, "flags should be one of 'r', 'w', 'c' or 'n'" raise error, "flags should be one of 'r', 'w', 'c' or 'n'"
return flags | db.DB_THREAD return flags | db.DB_THREAD
......
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