Skip to content

Conversation

townsend2010
Copy link
Contributor

Fixes #578

@codecov
Copy link

codecov bot commented May 20, 2019

Codecov Report

Merging #789 into master will increase coverage by 0.01%.
The diff coverage is 72.51%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/client/cli/cmd/transfer.h 100% <ø> (ø) ⬆️
include/multipass/ssh/sftp_client.h 0% <0%> (ø)
src/ssh/sftp_client.cpp 71.25% <71.25%> (ø)
src/client/cli/cmd/transfer.cpp 77.16% <76%> (+2.69%) ⬆️
src/daemon/daemon_config.cpp 48.21% <0%> (-1.79%) ⬇️
src/daemon/daemon.cpp 28.32% <0%> (-0.07%) ⬇️
include/multipass/virtual_machine_factory.h 0% <0%> (ø) ⬆️
include/multipass/utils.h 30.76% <0%> (ø) ⬆️
...tform/backends/qemu/qemu_virtual_machine_factory.h 0% <0%> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fbb2e9a...6577076. Read the comment docs.

@townsend2010 townsend2010 changed the title [WiP] Add stdin & stdout to transfer Add stdin & stdout to the transfer command May 20, 2019
@townsend2010
Copy link
Contributor Author

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 SCPClient stuff.

@ricab ricab self-requested a review May 22, 2019 16:25
@townsend2010 townsend2010 force-pushed the add-stdin-stdout-to-transfer branch from beb0adc to c08d536 Compare May 22, 2019 17:14
Copy link
Contributor

@gerboland gerboland left a 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.

Copy link
Collaborator

@ricab ricab left a 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

@townsend2010
Copy link
Contributor Author

@gerboland,

I can also reproduce the file size/md5sum issue, What is happening is that when reading from stdin, the code uses a QTextStream to read in the data, assuming it will be actual text from a terminal. However, in your scenario, you are redirecting binary data through cat and then QTextStream is interpreting that data.

I'll have to dig further to figure out whether 1) redirecting binary data is even supported in the sftp protocol, 2) if so, then figure out if cat is at fault or if it's QTextStream, and 3) if it's QTextStream, what a better solution would be.

@ricab
Copy link
Collaborator

ricab commented May 23, 2019

QTextStream

@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.
Copy link
Collaborator

@ricab ricab left a 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).

@gerboland
Copy link
Contributor

The transfer bug I noticed is fixed, thanks!

Copy link
Contributor

@gerboland gerboland left a 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};
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

bors r+

bors bot added a commit that referenced this pull request May 29, 2019
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]>
@bors
Copy link
Contributor

bors bot commented May 29, 2019

@bors bors bot merged commit 6577076 into master May 29, 2019
@bors bors bot deleted the add-stdin-stdout-to-transfer branch May 29, 2019 15:01
@townsend2010 townsend2010 mentioned this pull request May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

transfer should accept - as arguments for stdin/out
5 participants