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

Fix transfer only partially transferring #3902

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Sploder12
Copy link
Contributor

Fixes the issue of multipass transfer only transferring some chunks of the file. This uses sftp_limits instead of the constant 65536u to determine the correct buffer size for SFTP reads and writes.

Fixes #3892
MULTI-1768

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.11%. Comparing base (620770e) to head (3d9d0e6).
Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3902      +/-   ##
==========================================
- Coverage   89.11%   89.11%   -0.01%     
==========================================
  Files         255      255              
  Lines       14600    14602       +2     
==========================================
+ Hits        13011    13012       +1     
- Misses       1589     1590       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

levkropp
levkropp previously approved these changes Jan 29, 2025
Copy link
Contributor

@levkropp levkropp left a comment

Choose a reason for hiding this comment

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

Looks good on my end! Tested with the ingredients.tar.gz in the linked issue and they had the same md5sum after transferring

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.

Hey @Sploder12, good work. A couple of matters for discussion inline.

@@ -331,7 +330,8 @@ void SFTPClient::do_push_file(std::istream& source, const fs::path& target_path)
if (!remote_file)
throw SFTPError{"cannot open remote file {}: {}", target_path, ssh_get_error(sftp->session)};

std::array<char, max_transfer> buffer{};
const auto max_write = sftp_limits(sftp.get())->max_write_length;
std::vector<char> buffer(max_write);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't need to zero all the bytes, right? I wonder if we should do std::vector<char> buffer; buffer.reserve(max_write); instead, here and in the read case below (perhaps with a warning comment about the uninitialized data).

Also, this is a tricky constructor: if someone accidentally replaced the parenthesis with curly braces, it would create a vector with a single character. If you think we'd better keep, do you think it's worth a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that'd be undefined behavior. But std::unique_ptr<char[]> buffer{new char[max_write]}; should work.

Comment on lines 120 to 123
REPLACE(sftp_init, [this](sftp_session sftp) {
sftp->limits = &limits;
return SSH_OK;
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code is repeated many times. Would you mind extracting this into a separate function to call REPLACE with?

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.

multipass transfer only transfers half the file (every 2nd 32K block)
3 participants