-
Notifications
You must be signed in to change notification settings - Fork 151
path fixing when copying folders from windows #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
as window's file separator is '\', when copying folders from windows the destination path get malformed, replacing '\' with '/' is enough to solve it.
Hi there, thanks for the PR. If I understand correctly, In that case it would be more appropriate to not use |
Hi. imagine a windows folder called parent and with 2 files inside called childrenA.txt and childrenB.txt:
to access them python will use "parent\childrenA.txt" and "parent\childrenB.txt", if you are trying to copy parent to a remote sever, you will get 3 files:
when the expected behavior will be a single folder called "parent" with 2 files inside. |
Yes, I understand. The change needed here is for Replacing |
when copying files from or to a windows device, sub-directories structure is not being to be correctly replicated as linux doesn't use '\' as file separator. forcing the remote path to use '/' guarantees the paths are correctly replicated.
Hi again. sorry for the very late response, i have been busy upgrading a project. i just did the requested changes. i'd be happy if u can review it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, thanks for looking into this!
Reviewed, comments in line.
pssh/ssh_client.py
Outdated
@@ -364,7 +364,7 @@ def _copy_dir(self, local_dir, remote_dir, sftp): | |||
file_list = os.listdir(local_dir) | |||
for file_name in file_list: | |||
local_path = os.path.join(local_dir, file_name) | |||
remote_path = os.path.join(remote_dir, file_name) | |||
remote_path = remote_dir+'/'+file_name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better written as '/'.join([remote_dir, file_name])
.
String concatenation creates new strings on every operation (2 temporary + 1 final in the above case), which is a lot slower than a single join
call. This is done for every sub-dir and for every client in host list, so adds up quickly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but, isn't it creating a new array each time?
pssh/ssh_client.py
Outdated
@@ -455,7 +455,7 @@ def copy_remote_file(self, remote_file, local_file, recurse=False, | |||
def _copy_remote_dir(self, file_list, remote_dir, local_dir, sftp): | |||
for file_name in file_list: | |||
remote_path = os.path.join(remote_dir, file_name) | |||
local_path = os.path.join(local_dir, file_name) | |||
local_path = local_dir+'/'+file_name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remote_path
needs changing here, not local_path
(local_path
is local to client and platform specific). Looking at paramiko source confirms this.
Also same comment as above about '/'.join
.
replacing + on string concatenation by join.
changes are made |
pssh/ssh_client.py
Outdated
@@ -364,7 +364,7 @@ def _copy_dir(self, local_dir, remote_dir, sftp): | |||
file_list = os.listdir(local_dir) | |||
for file_name in file_list: | |||
local_path = os.path.join(local_dir, file_name) | |||
remote_path = os.path.join(remote_dir, file_name) | |||
remote_path = '/'.join([remote_dir,file_name]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flake errors: pssh/ssh_client.py:367:47: E231 missing whitespace after ','
Per https://travis-ci.org/ParallelSSH/parallel-ssh/jobs/279101695
pssh/ssh_client.py
Outdated
remote_path = os.path.join(remote_dir, file_name) | ||
local_path = os.path.join(local_dir, file_name) | ||
remote_path = '/'.join([remote_dir, file_name]) | ||
local_path = os.path.join(local_dir,file_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, changes look good. Only couple minor changes needed for the flake check to pass, see in line comments and CI job, looks ready otherwise. Thanks again for the PR. |
sure, no problem. |
Thanks for making these changes :) FYI, have found a couple more places where remote path needs changing for windows which are used when |
as window's file separator is '', when copying folders from windows the destination path get malformed, replacing '' with '/' is enough to solve it.