Treat empty dat/dir pairs as dumbdbm. Fixes #744687.

This commit is contained in:
Martin v. Löwis 2003-06-14 08:16:34 +00:00
parent 8316feb155
commit 17fb50790d
2 changed files with 12 additions and 3 deletions

View file

@ -50,15 +50,19 @@ def whichdb(filename):
# Check for dumbdbm next -- this has a .dir and and a .dat file
try:
f = open(filename + os.extsep + "dat", "rb")
f.close()
# First check for presence of files
sizes = os.stat(filename + os.extsep + "dat").st_size, \
os.stat(filename + os.extsep + "dir").st_size
# dumbdbm files with no keys are empty
if sizes == (0, 0):
return "dumbdbm"
f = open(filename + os.extsep + "dir", "rb")
try:
if f.read(1) in ["'", '"']:
return "dumbdbm"
finally:
f.close()
except IOError:
except (OSError, IOError):
pass
# See if the file exists, return None if not