Skip to content
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

Don't SFTP PUT directory contents twice #230

Merged
merged 2 commits into from
Apr 21, 2017
Merged

Conversation

amake
Copy link
Contributor

@amake amake commented Apr 18, 2017

This fixes #218 (put method generates "Failed SFTP MKDIR"), int128/gradle-ssh-plugin#285, and potentially #228.

When recursively gathering files to PUT, directory contents are apparently intended to be inspected separately depending on whether the child is a file or a dir:

  1. first, child files with File.eachFile
  2. then child dirs with File.eachDir

but the File.eachFile invocation used includes both files and directories, thus resulting in directories being gathered twice.

Steps to verify the fix

  1. Use the FilePut.put method with a from argument indicating a directory tree multiple levels deep
  2. Note that prior to the fix, subdirectories were traversed twice, while after the fix they are not (adding a logging statement to the Instructions class constructor makes this more apparent)
ssh.run {
  session(remotes.myremote) {
     put from: someFileTree, into: '/remote/dir'
  }
}

Backward compatibility

Other than eliminating redundant traversals, this fix changes the order of traversal: previously all items were traversed in lexicographical order, with directory-children interleaved with regular file-children (and then the directories were traversed a second time). Now, all file-children are traversed first, and then directory-children are traversed. This is what I gleaned to be the original intent of the code, based on the separate calls to File.eachFile and File.eachDir.

When recursively gathering files to PUT, directory contents are
apparently intended to be inspected twice:
1. child files with File.eachFile
2. child dirs with File.eachDir
but the File.eachFile invocation used includes both files and
directories, thus resulting in directories being gathered twice.

Fixes int128#218
@int128 int128 added the bug label Apr 19, 2017
@int128 int128 added this to the 2.9.0 milestone Apr 19, 2017
@matthiasbalke
Copy link

@amake Please update your PR, as another one was merged and your PR is not up to date anymore. Currently it cannot be merged.

@int128 int128 requested review from int128 and removed request for int128 April 21, 2017 13:53
@int128 int128 merged commit 5f05e65 into int128:master Apr 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

put method generates "Failed SFTP MKDIR"
3 participants