Skip to content

Commit e72d642

Browse files
committed
Revert part of remote_copy change to allow pathnames
This commit backs out some of the prior change to _SFTPFileCopier so that it still handles file opens prior to deciding whether to use remote_copy() or not. This seems to make a difference on Windows in particular to properly handle errors in a copy. Passing in either an open file or pathname is still supported. This change only changes where the file open happens in the case where _SFTPFileCopier is used.
1 parent 165c3b9 commit e72d642

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

asyncssh/sftp.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -801,22 +801,6 @@ async def run_task(self, offset: int, size: int) -> Tuple[int, int]:
801801
async def run(self) -> None:
802802
"""Perform parallel file copy"""
803803

804-
if self._srcfs == self._dstfs and \
805-
isinstance(self._srcfs, SFTPClient):
806-
try:
807-
await self._srcfs.remote_copy(self._srcpath, self._dstpath)
808-
except SFTPOpUnsupported:
809-
pass
810-
else:
811-
self._bytes_copied = self._total_bytes
812-
813-
if self._progress_handler:
814-
self._progress_handler(self._srcpath, self._dstpath,
815-
self._bytes_copied,
816-
self._total_bytes)
817-
818-
return
819-
820804
try:
821805
self._src = await self._srcfs.open(self._srcpath, 'rb',
822806
block_size=0)
@@ -826,6 +810,24 @@ async def run(self) -> None:
826810
if self._progress_handler and self._total_bytes == 0:
827811
self._progress_handler(self._srcpath, self._dstpath, 0, 0)
828812

813+
if self._srcfs == self._dstfs and \
814+
isinstance(self._srcfs, SFTPClient):
815+
try:
816+
await self._srcfs.remote_copy(
817+
cast(SFTPClientFile, self._src),
818+
cast(SFTPClientFile, self._dst))
819+
except SFTPOpUnsupported:
820+
pass
821+
else:
822+
self._bytes_copied = self._total_bytes
823+
824+
if self._progress_handler:
825+
self._progress_handler(self._srcpath, self._dstpath,
826+
self._bytes_copied,
827+
self._total_bytes)
828+
829+
return
830+
829831
async for _, datalen in self.iter():
830832
if datalen:
831833
self._bytes_copied += datalen

0 commit comments

Comments
 (0)