]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/hlinkdb.py
HLinkDB.__del__: replace with context management
[bup.git] / lib / bup / hlinkdb.py
index f953a32d321e2b9d3d634a09554c3ef1efa2eb9f..05a52ef01072e5974959e96f215e215610505b65 100644 (file)
@@ -3,6 +3,7 @@ from __future__ import absolute_import
 import errno, os, tempfile
 
 from bup import compat
+from bup.compat import pending_raise
 
 if compat.py_maj > 2:
     import pickle
@@ -92,8 +93,12 @@ class HLinkDB:
             os.unlink(self._tmpname)
             self._tmpname = None
 
-    def __del__(self):
-        self.abort_save()
+    def __enter__(self):
+        return self
+
+    def __exit__(self, type, value, traceback):
+        with pending_raise(value, rethrow=True):
+            self.abort_save()
 
     def add_path(self, path, dev, ino):
         # Assume path is new.