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

Fixed move semantics of DownloadAttempt #2963

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

JohanMabille
Copy link
Member

No description provided.

@JohanMabille JohanMabille marked this pull request as ready for review November 9, 2023 15:28
@JohanMabille JohanMabille changed the title Using DownloadAttempt as a value Fixed move semantics of DownloadAttempt Nov 9, 2023
Copy link
Member

@Klaim Klaim left a comment

Choose a reason for hiding this comment

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

LGTM, mostly have questions for details.

@@ -34,9 +34,11 @@ namespace mamba
using on_success_callback = std::function<bool(DownloadSuccess)>;
using on_failure_callback = std::function<bool(DownloadError)>;

explicit DownloadAttempt(const DownloadRequest& request);
DownloadAttempt() = default;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not totally sure but I think to link properly you need DownloadAttempt::DownloadAttempt()=default; in the cpp (moving the definition in the cpp).
If you get no link issues in msvc, ignore this comment.

on_success_callback m_success_callback;
on_failure_callback m_failure_callback;
std::size_t m_retry_wait_seconds = std::size_t(0);
std::unique_ptr<CompressionStream> p_stream = nullptr;
Copy link
Member

Choose a reason for hiding this comment

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

BTW can this be a normal member now? or an optional?

Copy link
Member Author

Choose a reason for hiding this comment

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

It cannot because CompressionStream is a polymorphic type.

std::string m_last_modified;
};

std::unique_ptr<Impl> p_impl = nullptr;
Copy link
Member

Choose a reason for hiding this comment

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

Note that it's already nullptr by default.

DownloadError build_download_error(TransferData data) const;
DownloadSuccess build_download_success(TransferData data) const;

CURLHandle* p_handle = nullptr;
Copy link
Member

Choose a reason for hiding this comment

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

Isnt handle already a value/pointer? Do you need to point to it?

Copy link
Member Author

@JohanMabille JohanMabille Nov 9, 2023

Choose a reason for hiding this comment

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

With this change, the handle is now a member (value) of DownloadTracker, to avoid recreating it each time we build an attempt. But the attempt still needs it, thus this pointer.

{
m_retry_wait_seconds = std::size_t(0);
return [impl = p_impl.get()](CURLMultiHandle& handle, CURLcode code)
Copy link
Member

Choose a reason for hiding this comment

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

If you find issues later with this lambda being called after impl have been destroyed, consider using task_synchronizer to guarantee that this does not ever happen.

@JohanMabille JohanMabille merged commit ed27c71 into mamba-org:main Nov 9, 2023
27 checks passed
@JohanMabille JohanMabille deleted the mirror_oci branch November 9, 2023 16:26
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.

2 participants