From: Martin v. Löwis Date: Sat, 14 Jun 2003 08:17:28 +0000 (+0000) Subject: Treat empty dat/dir files as dumbdbm. Fixes #744687. X-Git-Tag: 2.2~66 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=82866124bd088338ba766f5852f56293c62e3365;p=thirdparty%2FPython%2Fcpython.git Treat empty dat/dir files as dumbdbm. Fixes #744687. --- diff --git a/Lib/whichdb.py b/Lib/whichdb.py index 8b31003d9b18..fba7ccc8423c 100644 --- a/Lib/whichdb.py +++ b/Lib/whichdb.py @@ -29,15 +29,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