Skip to content

Commit 3dbb82e

Browse files
committed
fixed bug; if remote dir already exists, do not create it
1 parent 79d3685 commit 3dbb82e

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

ev3devcmd/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import errno
12
import socket
23
import paramiko
34
import rpyc
@@ -459,6 +460,18 @@ def new_rmdir(remote_path):
459460
orig_rmdir(remote_path)
460461

461462

463+
def rexists(sftp, path):
464+
"""os.path.exists for paramiko's sftp object
465+
"""
466+
try:
467+
sftp.stat(path)
468+
except IOError as e:
469+
if e.errno == errno.ENOENT:
470+
return False
471+
raise
472+
else:
473+
return True
474+
462475
def base_mirror(args,local_path,dest_path,mkdir_dest=False,rmdir_dest=False):
463476
# do extra connect only for nice error message in case of failure (don't want to hack sftpclone library for that)
464477
ssh=sshconnect(args)
@@ -500,7 +513,7 @@ def base_mirror(args,local_path,dest_path,mkdir_dest=False,rmdir_dest=False):
500513
orig_rmdir=sync.sftp.rmdir
501514
sync.sftp.rmdir=new_rmdir
502515

503-
if mkdir_dest:
516+
if mkdir_dest and not rexists(sync.sftp,dest_path):
504517
try:
505518
sync.sftp.mkdir(dest_path)
506519
except Exception as ex:

0 commit comments

Comments
 (0)