From 2c21b72117cdbfa84fa2302555685574bab1c33a Mon Sep 17 00:00:00 2001 From: Stephen L Date: Mon, 7 Aug 2017 17:17:45 +0200 Subject: [PATCH] fix deletion of database files with dumbdbm sfdict.close(delete=True) + bump version 0.6.5 Signed-off-by: Stephen L. --- fdict/_version.py | 2 +- fdict/fdict.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/fdict/_version.py b/fdict/_version.py index 7850a1d..afabed9 100644 --- a/fdict/_version.py +++ b/fdict/_version.py @@ -3,7 +3,7 @@ __all__ = ["__version__"] # major, minor, patch, -extra -version_info = 0, 6, 4 +version_info = 0, 6, 5 # Nice string for the version __version__ = '.'.join(map(str, version_info)) diff --git a/fdict/fdict.py b/fdict/fdict.py index f3c52af..0e39163 100644 --- a/fdict/fdict.py +++ b/fdict/fdict.py @@ -707,6 +707,7 @@ def __init__(self, *args, **kwargs): # Force the use of dumb dbm even if slower raise ImportError('pass') d = shelve.open(filename=self.filename, flag='c', protocol=PICKLE_HIGHEST_PROTOCOL, writeback=self.writeback) + self.usedumbdbm = False except (ImportError, IOError) as exc: if 'pass' in str(exc).lower() or '_bsddb' in str(exc).lower() or 'permission denied' in str(exc).lower(): # Pypy error, we workaround by using a fallback to anydbm: dumbdbm @@ -718,6 +719,7 @@ def __init__(self, *args, **kwargs): db = dumbdbm.open(self.filename, 'c') # Open the dumb db as a shelf d = shelve.Shelf(db, protocol=PICKLE_HIGHEST_PROTOCOL, writeback=self.writeback) + self.usedumbdbm = True else: # pragma: no cover raise @@ -749,6 +751,13 @@ def close(self, delete=False): self.d.close() if delete: try: - os.remove(self.get_filename()) - except Exception: + filename = self.get_filename() + if not self.usedumbdbm: + os.remove(filename) + else: + os.remove(filename+'.dat') + os.remove(filename+'.dir') + if os.path.exists(filename+'.bak'): # pragma: no cover + os.remove(filename+'.bak') + except Exception: # pragma: no cover pass