فهرست منبع

close the repo on exit - even if rollback did not work, fixes #1197

Thomas Waldmann 9 سال پیش
والد
کامیت
9725c03299
1فایلهای تغییر یافته به همراه8 افزوده شده و 3 حذف شده
  1. 8 3
      borg/remote.py

+ 8 - 3
borg/remote.py

@@ -189,9 +189,14 @@ class RemoteRepository:
         return self
         return self
 
 
     def __exit__(self, exc_type, exc_val, exc_tb):
     def __exit__(self, exc_type, exc_val, exc_tb):
-        if exc_type is not None:
-            self.rollback()
-        self.close()
+        try:
+            if exc_type is not None:
+                self.rollback()
+        finally:
+            # in any case, we want to cleanly close the repo, even if the
+            # rollback can not succeed (e.g. because the connection was
+            # already closed) and raised another exception:
+            self.close()
 
 
     def borg_cmd(self, args, testing):
     def borg_cmd(self, args, testing):
         """return a borg serve command line"""
         """return a borg serve command line"""