瀏覽代碼

RemoteRepository: clean up pipe if remote open() fails

Marian Beermann 9 年之前
父節點
當前提交
890e44ef60
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      borg/remote.py

+ 6 - 1
borg/remote.py

@@ -81,6 +81,7 @@ class RepositoryServer:  # pragma: no cover
                 unpacker.feed(data)
                 unpacker.feed(data)
                 for unpacked in unpacker:
                 for unpacked in unpacker:
                     if not (isinstance(unpacked, tuple) and len(unpacked) == 4):
                     if not (isinstance(unpacked, tuple) and len(unpacked) == 4):
+                        self.repository.close()
                         raise Exception("Unexpected RPC data format.")
                         raise Exception("Unexpected RPC data format.")
                     type, msgid, method, args = unpacked
                     type, msgid, method, args = unpacked
                     method = method.decode('ascii')
                     method = method.decode('ascii')
@@ -165,7 +166,11 @@ class RemoteRepository:
             raise ConnectionClosedWithHint('Is borg working on the server?') from None
             raise ConnectionClosedWithHint('Is borg working on the server?') from None
         if version != RPC_PROTOCOL_VERSION:
         if version != RPC_PROTOCOL_VERSION:
             raise Exception('Server insisted on using unsupported protocol version %d' % version)
             raise Exception('Server insisted on using unsupported protocol version %d' % version)
-        self.id = self.call('open', location.path, create, lock_wait, lock)
+        try:
+            self.id = self.call('open', self.location.path, create, lock_wait, lock)
+        except Exception:
+            self.close()
+            raise
 
 
     def __del__(self):
     def __del__(self):
         self.close()
         self.close()