]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Treat empty dat/dir files as dumbdbm. Fixes #744687.
authorMartin v. Löwis <martin@v.loewis.de>
Sat, 14 Jun 2003 08:17:28 +0000 (08:17 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sat, 14 Jun 2003 08:17:28 +0000 (08:17 +0000)
Lib/whichdb.py

index 8b31003d9b186d20e941e1df23dfc20a3c815809..fba7ccc8423cdab68a68ab395a198a8e6c3aedd6 100644 (file)
@@ -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