-
Notifications
You must be signed in to change notification settings - Fork 727
Add stdin & stdout to the transfer command #789
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
This includes running clang-format on all of the changed code.
Codecov Report
@@ Coverage Diff @@
## master #789 +/- ##
=========================================
+ Coverage 68.69% 68.7% +0.01%
=========================================
Files 177 181 +4
Lines 6273 6403 +130
=========================================
+ Hits 4309 4399 +90
- Misses 1964 2004 +40
Continue to review full report at Codecov.
|
Ok, let's see about getting this in its current form. I plan on switching over to just using this for all types of transfers and remove the |
beb0adc
to
c08d536
Compare
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 an excellent feature, thank you. Many thanks for all the additional tests too.
I've only a couple of minor niggles found in the code, which I've reported.
Functionally I've one main concern: I've noticed sometimes files fail to transfer correctly. In my build directory I did:
cat ./bin/text_to_string_array | ./bin/multipass transfer - x:/home/multipass/text_to_string_array
and then I compared file sizes and md5sums. Sometimes I found the transferred file was different to the original.
Host:
$ ls -l bin/text_to_string_array
-rwxrwxr-x 1 gerry gerry 137472 May 10 14:23 bin/text_to_string_array
and in VM:
x: $ ls -l text_to_string_array
-rwxrwxr-x 1 multipass multipass 157010 May 23 11:37 text_to_string_array
I'm trying to identify a pattern, as it only appears to happen with some files that I try. Can you reproduce?
A smaller functional complaint is that if you do something silly like trying to transfer into a directory
cat ./bin/text_to_string_array | ./bin/multipass transfer - x:/home/multipass
transfer failed: [sftp stream] open failed: 'SFTP server: Failure'
the error message isn't great.
Would there be value in checking the destination is valid before trying a transfer? And maybe prompting before possibly overwriting existing files?
But I'm not expecting a perfect UX in this MP. If you can reproduce and resolve the file copy problem I see, that would be good enough for this PR.
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.
Thank you for the contribution! I find this adds very worthwhile value and is well coded in general. Very helpful 🙂
There are some non-central things I would like to see improved, but I think this is very close to being in a good state for inclusion. My main concerns are:
- mocking stdin/stdout -> relying on C++ api for IO
- terminology (e.g. things like
template
did not make much sense to me) - security: I would recommend getting another careful look focusing on security before merging
I can also reproduce the file size/md5sum issue, What is happening is that when reading from I'll have to dig further to figure out whether 1) redirecting binary data is even supported in the |
@townsend2010 I believe this would be covered by a move to std::istream, which I suppose would be part of abstracting cin/cout for mocking. See this comment. |
- Use the istream/ostream from the Terminal class for stdio. - Clean up the logic around trying to figure out if '-' is used. - Add more tests for streaming to stdout. - Some other code optimizations.
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.
Very nice, thanks a lot! This is now in very good shape.
I have only some comments/questions and a few very simple requests (and one pending from last review).
The transfer bug I noticed is fixed, thanks! |
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.
Overall looks good! I'm happy to approve this as-is
{ | ||
auto full_destination_path = full_destination(destination_path, mp::utils::filename_for(source_path)); | ||
SFTPFileUPtr file_handle{ | ||
sftp_open(sftp.get(), full_destination_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, file_mode), sftp_close}; |
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.
My only concern is how easily we overwrite files. Or am I being too nanny-ish?
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.
So did an experiment to see what the actual sftp
client does and it will just overwrite the old file with the new file without asking. So I think it's ok to leave as-is, but perhaps if it becomes an issue, we can do something about it in the future.
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.
Nice 👍
bors r+
789: Add stdin & stdout to the transfer command r=ricab a=townsend2010 Fixes #578 Co-authored-by: MaximDanilov <[email protected]> Co-authored-by: Chris Townsend <[email protected]>
Build succeeded |
Fixes #578