1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-25 17:27:31 +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"""
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
rpc_methods = (
'__len__',
@ -79,13 +87,18 @@ def serve(self):
if r:
data = os.read(stdin_fd, BUFSIZE)
if not data:
self.repository.close()
if self.repository is not None:
self.repository.close()
else:
os.write(stderr_fd, "Borg {}: Got connection close before repository was opened.\n"
.format(__version__).encode())
return
unpacker.feed(data)
for unpacked in unpacker:
if not (isinstance(unpacked, tuple) and len(unpacked) == 4):
self.repository.close()
raise Exception("Unexpected RPC data format.")
if self.repository is not None:
self.repository.close()
raise UnexpectedRPCDataFormatFromClient(__version__)
type, msgid, method, args = unpacked
method = method.decode('ascii')
try:
@ -326,7 +339,7 @@ def handle_error(error, res):
self.unpacker.feed(data)
for unpacked in self.unpacker:
if not (isinstance(unpacked, tuple) and len(unpacked) == 4):
raise Exception("Unexpected RPC data format.")
raise UnexpectedRPCDataFormatFromServer()
type, msgid, error, res = unpacked
if msgid in self.ignore_responses:
self.ignore_responses.remove(msgid)