Skip to content

Commit

Permalink
fix deletion of database files with dumbdbm sfdict.close(delete=True)…
Browse files Browse the repository at this point in the history
… + bump version 0.6.5

Signed-off-by: Stephen L. <[email protected]>
  • Loading branch information
lrq3000 committed Aug 7, 2017
1 parent 59d3f5c commit 2c21b72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion fdict/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
13 changes: 11 additions & 2 deletions fdict/fdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 2c21b72

Please sign in to comment.