plugin misc file: fix getDestDir returning a Deferred in a coroutine
This commit is contained in:
parent
47d258e841
commit
fb310c104c
1 changed files with 12 additions and 22 deletions
|
|
@ -237,8 +237,8 @@ class FilePlugin:
|
|||
data_cb=file_data.get("data_cb"),
|
||||
)
|
||||
|
||||
def _gotConfirmation(
|
||||
self, data, client, peer_jid, transfer_data, file_data, stream_object
|
||||
async def _gotConfirmation(
|
||||
self, client, data, peer_jid, transfer_data, file_data, stream_object
|
||||
):
|
||||
"""Called when the permission and dest path have been received
|
||||
|
||||
|
|
@ -258,19 +258,7 @@ class FilePlugin:
|
|||
|
||||
# we manage case where file already exists
|
||||
if os.path.exists(file_path):
|
||||
|
||||
def check_overwrite(overwrite):
|
||||
if overwrite:
|
||||
self.openFileWrite(
|
||||
client, file_path, transfer_data, file_data, stream_object
|
||||
)
|
||||
return True
|
||||
else:
|
||||
return defer.ensureDeferred(
|
||||
self.getDestDir(client, peer_jid, transfer_data, file_data)
|
||||
)
|
||||
|
||||
exists_d = xml_tools.deferConfirm(
|
||||
overwrite = await xml_tools.deferConfirm(
|
||||
self.host,
|
||||
_(CONFIRM_OVERWRITE).format(file_path),
|
||||
_(CONFIRM_OVERWRITE_TITLE),
|
||||
|
|
@ -282,8 +270,9 @@ class FilePlugin:
|
|||
security_limit=SECURITY_LIMIT,
|
||||
profile=client.profile,
|
||||
)
|
||||
exists_d.addCallback(check_overwrite)
|
||||
return exists_d
|
||||
|
||||
if not overwrite:
|
||||
return await self.getDestDir(client, peer_jid, transfer_data, file_data)
|
||||
|
||||
self.openFileWrite(client, file_path, transfer_data, file_data, stream_object)
|
||||
return True
|
||||
|
|
@ -315,7 +304,7 @@ class FilePlugin:
|
|||
"size_human" will also be added with human readable file size
|
||||
@param stream_object(bool): if True, a stream_object will be used instead of file_obj
|
||||
a stream.FileStreamObject will be used
|
||||
return (defer.Deferred): True if transfer is accepted
|
||||
return: True if transfer is accepted
|
||||
"""
|
||||
cont, ret_value = await self.host.trigger.asyncReturnPoint(
|
||||
"FILE_getDestDir", client, peer_jid, transfer_data, file_data, stream_object
|
||||
|
|
@ -327,7 +316,7 @@ class FilePlugin:
|
|||
assert PROGRESS_ID_KEY in file_data
|
||||
# human readable size
|
||||
file_data["size_human"] = common_utils.getHumanSize(file_data["size"])
|
||||
d = xml_tools.deferDialog(
|
||||
resp_data = await xml_tools.deferDialog(
|
||||
self.host,
|
||||
_(CONFIRM).format(peer=peer_jid.full(), **file_data),
|
||||
_(CONFIRM_TITLE),
|
||||
|
|
@ -341,12 +330,13 @@ class FilePlugin:
|
|||
security_limit=SECURITY_LIMIT,
|
||||
profile=client.profile,
|
||||
)
|
||||
d.addCallback(
|
||||
self._gotConfirmation,
|
||||
|
||||
accepted = await self._gotConfirmation(
|
||||
client,
|
||||
resp_data,
|
||||
peer_jid,
|
||||
transfer_data,
|
||||
file_data,
|
||||
stream_object,
|
||||
)
|
||||
return d
|
||||
return accepted
|
||||
|
|
|
|||
Loading…
Reference in a new issue