1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-27 10:18:12 +00:00

Merge pull request #1525 from textshell/fix/remote-manual-ssh

borg serve throws exception while trying to close when it gets eof at start
This commit is contained in:
TW 2016-08-24 14:09:06 +02:00 committed by GitHub
commit 17bd6e0ef4

View file

@ -37,6 +37,14 @@ class InvalidRPCMethod(Error):
"""RPC method {} is not valid""" """RPC method {} is not valid"""
class UnexpectedRPCDataFormatFromClient(Error):
"""Borg {}: Got unexpected RPC data format from client."""
class UnexpectedRPCDataFormatFromServer(Error):
"""Got unexpected RPC data format from server."""
class RepositoryServer: # pragma: no cover class RepositoryServer: # pragma: no cover
rpc_methods = ( rpc_methods = (
'__len__', '__len__',
@ -79,13 +87,18 @@ def serve(self):
if r: if r:
data = os.read(stdin_fd, BUFSIZE) data = os.read(stdin_fd, BUFSIZE)
if not data: if not data:
if self.repository is not None:
self.repository.close() self.repository.close()
else:
os.write(stderr_fd, "Borg {}: Got connection close before repository was opened.\n"
.format(__version__).encode())
return return
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):
if self.repository is not None:
self.repository.close() self.repository.close()
raise Exception("Unexpected RPC data format.") raise UnexpectedRPCDataFormatFromClient(__version__)
type, msgid, method, args = unpacked type, msgid, method, args = unpacked
method = method.decode('ascii') method = method.decode('ascii')
try: try:
@ -326,7 +339,7 @@ def handle_error(error, res):
self.unpacker.feed(data) self.unpacker.feed(data)
for unpacked in self.unpacker: for unpacked in self.unpacker:
if not (isinstance(unpacked, tuple) and len(unpacked) == 4): if not (isinstance(unpacked, tuple) and len(unpacked) == 4):
raise Exception("Unexpected RPC data format.") raise UnexpectedRPCDataFormatFromServer()
type, msgid, error, res = unpacked type, msgid, error, res = unpacked
if msgid in self.ignore_responses: if msgid in self.ignore_responses:
self.ignore_responses.remove(msgid) self.ignore_responses.remove(msgid)