Skip to content

Commit d60ae66

Browse files
Caid11pkittenis
authored andcommitted
Fixed _parent_path_split method and included it where some code was duplicated.
1 parent 0533d1e commit d60ae66

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pssh/ssh_client.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ def copy_file(self, local_file, remote_file, recurse=False):
361361
"directory.")
362362
sftp = self._make_sftp()
363363
destination = self._parent_path_split(remote_file)
364-
if os.path.sep in remote_file:
364+
try:
365+
sftp.stat(destination)
366+
except IOError:
365367
self.mkdir(sftp, destination)
366368
sftp.chdir()
367369
try:
@@ -427,8 +429,11 @@ def copy_file_to_local(self, remote_file, local_file, recurse=False):
427429

428430
@staticmethod
429431
def _parent_path_split(file_path):
430-
destination = [_dir for _dir in file_path.split(os.path.sep)
431-
if _dir][:-1][0]
432-
if file_path.startswith(os.path.sep):
432+
try:
433+
destination = [_dir for _dir in file_path.split(os.path.sep)
434+
if _dir][:-1][0]
435+
except IndexError:
436+
destination = ''
437+
if file_path.startswith(os.path.sep) or not destination:
433438
destination = os.path.sep + destination
434439
return destination

0 commit comments

Comments
 (0)