Skip to content

Commit

Permalink
Structure fetch code and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Hind-M committed Apr 13, 2023
1 parent dac5d9e commit ba38f0a
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 99 deletions.
57 changes: 32 additions & 25 deletions libmamba/include/mamba/core/fetch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,21 @@ namespace mamba
void set_expected_size(std::size_t size);
void set_head_only(bool yes);

const std::string& name() const;
const std::string& url() const;
std::size_t expected_size() const;
std::string get_name() const;
std::string get_url() const;

void init_curl_ssl();
void init_curl_target(const std::string& url);
std::string get_etag() const;
std::string get_mod() const;
std::string get_cache_control() const;

bool resource_exists();
bool perform();
CURL* handle();
std::size_t get_expected_size() const;
int get_http_status() const;
std::size_t get_downloaded_size() const;

curl_off_t get_speed();
std::size_t get_speed();

void init_curl_ssl();
void init_curl_target(const std::string& url);

template <class C>
inline void set_finalize_callback(bool (C::*cb)(const DownloadTarget&), C* data)
Expand All @@ -80,12 +83,18 @@ namespace mamba
m_ignore_failure = yes;
}

bool ignore_failure() const
bool get_ignore_failure() const
{
return m_ignore_failure;
}

void set_result(CURLcode r);
std::size_t get_result() const;

bool resource_exists();
bool perform();
CURL* handle();

bool finalize();
std::string get_transfer_msg();

Expand All @@ -95,16 +104,6 @@ namespace mamba
std::chrono::steady_clock::time_point progress_throttle_time() const;
void set_progress_throttle_time(const std::chrono::steady_clock::time_point& time);

CURLcode result = CURLE_OK;
bool failed = false;
int http_status = 10000;
char* effective_url = nullptr;
curl_off_t downloaded_size = 0;
curl_off_t avg_speed = 0;
std::string final_url;

std::string etag, mod, cache_control;

private:

std::unique_ptr<ZstdStream> m_zstd_stream;
Expand All @@ -114,16 +113,24 @@ namespace mamba

std::string m_name, m_filename, m_url;

int m_http_status;
std::size_t m_downloaded_size;
char* m_effective_url;

CURLcode m_result; // Enum range from 0 to 99

std::string m_etag, m_mod, m_cache_control;

// validation
std::size_t m_expected_size = 0;
std::size_t m_expected_size;

// retry & backoff
std::chrono::steady_clock::time_point m_next_retry;
std::size_t m_retry_wait_seconds = get_default_retry_timeout();
std::size_t m_retries = 0;
std::size_t m_retry_wait_seconds;
std::size_t m_retries;

bool m_has_progress_bar = false;
bool m_ignore_failure = false;
bool m_has_progress_bar;
bool m_ignore_failure;

ProgressProxy m_progress_bar;

Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/api/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ namespace mamba
tmp_lock_file = std::make_unique<TemporaryFile>();
DownloadTarget dt("Environment Lockfile", lockfile, tmp_lock_file->path());
bool success = dt.perform();
if (!success || dt.http_status != 200)
if (!success || dt.get_http_status() != 200)
{
throw std::runtime_error(
fmt::format("Could not download environment lockfile from {}", lockfile)
Expand Down
Loading

0 comments on commit ba38f0a

Please sign in to comment.