diff options
| author | Martin v. Löwis <martin@v.loewis.de> | 2003-06-14 08:16:34 +0000 |
|---|---|---|
| committer | Martin v. Löwis <martin@v.loewis.de> | 2003-06-14 08:16:34 +0000 |
| commit | 36dbe1933bdee1bf28ef89063e7ca85edeadbbf8 (patch) | |
| tree | 1a1a19bb32fadade87945fdb74de52bc07e535e0 /Lib/whichdb.py | |
| parent | 247ef738edc404af9490657b13f9e63699b7de88 (diff) | |
| download | cpython-36dbe1933bdee1bf28ef89063e7ca85edeadbbf8.tar.gz | |
Treat empty dat/dir pairs as dumbdbm. Fixes #744687.
Diffstat (limited to 'Lib/whichdb.py')
| -rw-r--r-- | Lib/whichdb.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/whichdb.py b/Lib/whichdb.py index fed58e943b..92996367ee 100644 --- a/Lib/whichdb.py +++ b/Lib/whichdb.py @@ -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 |
