rx: don't reveal file-already-exists, just reject transfer

closes #74
This commit is contained in:
Brian Warner 2016-12-08 16:50:00 -08:00
parent ab972785aa
commit 582cebfb5f
2 changed files with 8 additions and 4 deletions

View File

@ -16,6 +16,10 @@ class RespondError(Exception):
def __init__(self, response):
self.response = response
class TransferRejectedError(RespondError):
def __init__(self):
RespondError.__init__(self, "transfer rejected")
def receive(args, reactor=reactor):
"""I implement 'wormhole receive'. I return a Deferred that fires with
None (for success), or signals one of the following errors:
@ -230,7 +234,7 @@ class TwistedReceiver:
if os.path.exists(abs_destname):
self._msg(u"Error: refusing to overwrite existing %s %s" %
(mode, destname))
raise RespondError("%s already exists" % mode)
raise TransferRejectedError()
return abs_destname
def _ask_permission(self):
@ -241,7 +245,7 @@ class TwistedReceiver:
break
print(u"transfer rejected", file=sys.stderr)
t.detail(answer="no")
raise RespondError("transfer rejected")
raise TransferRejectedError()
t.detail(answer="yes")
def _send_permission(self, w):

View File

@ -491,10 +491,10 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
# both sides will fail because of the pre-existing file
f = yield self.assertFailure(send_d, TransferError)
self.assertEqual(str(f), "remote error, transfer abandoned: file already exists")
self.assertEqual(str(f), "remote error, transfer abandoned: transfer rejected")
f = yield self.assertFailure(receive_d, TransferError)
self.assertEqual(str(f), "file already exists")
self.assertEqual(str(f), "transfer rejected")
send_stdout = send_cfg.stdout.getvalue()
send_stderr = send_cfg.stderr.getvalue()